Skip to content

Commit

Permalink
Do not pass keywords that cannot be handled to super
Browse files Browse the repository at this point in the history
  • Loading branch information
flash-gordon committed Jan 7, 2025
1 parent 7b33e16 commit c795b54
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/dry/auto_inject/method_parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ def splat?
@splat = parameters.any? { |type, _| type == :rest }
end

def keyword_splat?
return @keyword_splat if defined? @keyword_splat

@keyword_splat = parameters.any? { |type, _| type == :keyrest }
end

def sequential_arguments?
return @sequential_arguments if defined? @sequential_arguments

Expand All @@ -59,6 +65,10 @@ def keyword?(name)
keyword_names.include?(name)
end

def accept_keyword?(name)
keyword_splat? || keyword?(name)
end

def empty?
parameters.empty?
end
Expand Down
8 changes: 6 additions & 2 deletions lib/dry/auto_inject/strategies/kwargs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def define_initialize_with_splat(super_parameters)
else
super_kwargs = slice_kwargs.(kwargs, super_parameters)

if super_kwargs.any? && super_parameters.keyword_names.any?
if super_kwargs.any?
super(*args, **super_kwargs, &block)
else
super(*args, &block)
Expand All @@ -92,7 +92,11 @@ def assign_dependencies(kwargs, destination)

def slice_kwargs(kwargs, super_parameters)
kwargs.select do |key|
!dependency_map.names.include?(key) || super_parameters.keyword?(key)
if super_parameters.accept_keyword?(key)
!dependency_map.names.include?(key) || super_parameters.keyword?(key)
else
false
end
end
end
end
Expand Down

0 comments on commit c795b54

Please sign in to comment.