Skip to content

Commit

Permalink
Merge pull request #70 from criteo-cookbooks/kwargs_deleg_ruby_v2_v3_…
Browse files Browse the repository at this point in the history
…compat

Make keyword arguments delegation compatible with ruby v3
  • Loading branch information
Annih authored Nov 24, 2022
2 parents 8c35045 + 84d8c55 commit 394814f
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions libraries/choregraphie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ def initialize(name, &block)
# read all available primitives and make them available with a method
# using their name. It allows to call `check_file '/tmp/titi'` to
# instantiate the CheckFile primitive
delegated_args = RUBY_VERSION.to_i < 3 ? '*args, &block' : '*args, **kwargs, &block'
Primitive.all.each do |klass|
instance_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{klass.primitive_name}(*args, &block)
primitive = ::#{klass}.new(*args, &block)
def #{klass.primitive_name}(#{delegated_args})
primitive = ::#{klass}.new(#{delegated_args})
@primitives << primitive
primitive.register(self)
end
Expand Down Expand Up @@ -75,8 +76,14 @@ def #{klass.primitive_name}(*args, &block)
instance_eval(&block)
end

def method_missing(method, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@self_before_instance_eval.send method, *args, &block
if RUBY_VERSION.to_i < 3
def method_missing(method, *args, &block) # rubocop:disable Style/MissingRespondToMissing
@self_before_instance_eval.send method, *args, &block
end
else
def method_missing(method, *args, **kwargs, &block) # rubocop:disable Style/MissingRespondToMissing
@self_before_instance_eval.send method, *args, **kwargs, &block
end
end

def cleanup_block_name(resource_name)
Expand Down

0 comments on commit 394814f

Please sign in to comment.