Skip to content

Commit 36bd065

Browse files
committed
Clean up conditionals based on prior Ruby versions
Used standardrb in the process, so update the minimum Ruby version to 3.0 for this to work.
1 parent 211c088 commit 36bd065

File tree

7 files changed

+16
-29
lines changed

7 files changed

+16
-29
lines changed

.standard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
ruby_version: "2.5"
1+
ruby_version: "3.0"

lib/factory_bot/decorator.rb

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,12 @@ def initialize(component)
66
@component = component
77
end
88

9-
if ::Gem::Version.new(::RUBY_VERSION) >= ::Gem::Version.new("2.7")
10-
class_eval(<<~RUBY, __FILE__, __LINE__ + 1)
11-
def method_missing(...) # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
12-
@component.send(...)
13-
end
14-
15-
def send(...)
16-
__send__(...)
17-
end
18-
RUBY
19-
else
20-
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
21-
@component.send(name, *args, &block)
22-
end
9+
def method_missing(...) # rubocop:disable Style/MethodMissingSuper
10+
@component.send(...)
11+
end
2312

24-
def send(symbol, *args, &block)
25-
__send__(symbol, *args, &block)
26-
end
13+
def send(...)
14+
__send__(...)
2715
end
2816

2917
def respond_to_missing?(name, include_private = false)

lib/factory_bot/definition_proxy.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondTo
119119
# end
120120
#
121121
# Except that no globally available sequence will be defined.
122-
def sequence(name, *args, &block)
123-
sequence = Sequence.new(name, *args, &block)
122+
def sequence(name, ...)
123+
sequence = Sequence.new(name, ...)
124124
FactoryBot::Internal.register_inline_sequence(sequence)
125125
add_attribute(name) { increment_sequence(sequence) }
126126
end

lib/factory_bot/evaluator.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ def association(factory_name, *traits_and_overrides)
3535

3636
attr_accessor :instance
3737

38-
def method_missing(method_name, *args, &block)
38+
def method_missing(method_name, ...)
3939
if @instance.respond_to?(method_name)
40-
@instance.send(method_name, *args, &block)
40+
@instance.send(method_name, ...)
4141
else
42-
SyntaxRunner.new.send(method_name, *args, &block)
42+
SyntaxRunner.new.send(method_name, ...)
4343
end
4444
end
45-
ruby2_keywords :method_missing if respond_to?(:ruby2_keywords, true)
4645

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

lib/factory_bot/syntax/default.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def factory(name, options = {}, &block)
2525
end
2626
end
2727

28-
def sequence(name, *args, &block)
29-
Internal.register_sequence(Sequence.new(name, *args, &block))
28+
def sequence(name, ...)
29+
Internal.register_sequence(Sequence.new(name, ...))
3030
end
3131

3232
def trait(name, &block)

spec/acceptance/attributes_for_destructuring.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
it "supports being destructured" do
1616
# rubocop:disable Lint/Syntax
1717
attributes_for(:user) => {name:, **attributes}
18-
# rubocop:disable Lint/Syntax
18+
# rubocop:enable Lint/Syntax
1919

2020
expect(name).to eq("John Doe")
2121
expect(attributes.keys).to eq([:email])

spec/acceptance/attributes_for_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
if RUBY_VERSION >= "3.0" && RUBY_ENGINE != "truffleruby"
2-
require_relative "./attributes_for_destructuring"
1+
if RUBY_ENGINE != "truffleruby"
2+
require_relative "attributes_for_destructuring"
33
end
44

55
describe "a generated attributes hash" do

0 commit comments

Comments
 (0)