Skip to content

Commit

Permalink
Fix delegation
Browse files Browse the repository at this point in the history
* (*args, **kwargs) is incorrect in 2.7, only ruby2_keywords works on 2.7.
* See https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/
  • Loading branch information
eregon authored and composerinteralia committed May 7, 2021
1 parent b6606ab commit 6f3fe87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
19 changes: 4 additions & 15 deletions lib/factory_bot/decorator/invocation_tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,11 @@ def initialize(component)
@invoked_methods = []
end

if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("3.0")
def method_missing(name, *args, **kwargs, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
elsif ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
ruby2_keywords def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
else
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@invoked_methods << name
super
end
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)

def __invoked_methods__
@invoked_methods.uniq
Expand Down
21 changes: 6 additions & 15 deletions lib/factory_bot/evaluator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,14 @@ def association(factory_name, *traits_and_overrides)

attr_accessor :instance

if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
def method_missing(method_name, *args, **kwargs, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
if @instance.respond_to?(method_name)
@instance.send(method_name, *args, **kwargs, &block)
else
SyntaxRunner.new.send(method_name, *args, **kwargs, &block)
end
end
else
def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
if @instance.respond_to?(method_name)
@instance.send(method_name, *args, &block)
else
SyntaxRunner.new.send(method_name, *args, &block)
end
def method_missing(method_name, *args, &block) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
if @instance.respond_to?(method_name)
@instance.send(method_name, *args, &block)
else
SyntaxRunner.new.send(method_name, *args, &block)
end
end
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)

def respond_to_missing?(method_name, _include_private = false)
@instance.respond_to?(method_name) || SyntaxRunner.new.respond_to?(method_name)
Expand Down

0 comments on commit 6f3fe87

Please sign in to comment.