Skip to content

Commit

Permalink
Update crutch.rb
Browse files Browse the repository at this point in the history
Adds support for passing all crutches into a crutch definition, to be able to form a chain of crutches such that a field can depend and load only what it needs, instead of loading multiple objects at times, which might not all be required always.
  • Loading branch information
akshay58538 authored Sep 9, 2024
1 parent d2c38f7 commit 59d0fee
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/chewy/index/crutch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ def respond_to_missing?(name, include_private = false)
end

def [](name)
@crutches_instances[name] ||= @index._crutches[:"#{name}"].call(@collection)
execution_block = @index._crutches[:"#{name}"]
if execution_block.arity == 2
@crutches_instances[name] ||= execution_block.call(@collection, self)
else
@crutches_instances[name] ||= execution_block.call(@collection)
end
end
end

Expand Down

0 comments on commit 59d0fee

Please sign in to comment.