Class: Chewy::Index::Crutch::Crutches

Inherits:
Object
  • Object
show all
Defined in:
lib/chewy/index/crutch.rb

Instance Method Summary collapse

Constructor Details

#initialize(index, collection) ⇒ Crutches

Returns a new instance of Crutches.



12
13
14
15
16
# File 'lib/chewy/index/crutch.rb', line 12

def initialize(index, collection)
  @index = index
  @collection = collection
  @crutches_instances = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object



18
19
20
21
22
# File 'lib/chewy/index/crutch.rb', line 18

def method_missing(name, *, **)
  return self[name] if @index._crutches.key?(name)

  super
end

Instance Method Details

#[](name) ⇒ Object



28
29
30
# File 'lib/chewy/index/crutch.rb', line 28

def [](name)
  @crutches_instances[name] ||= @index._crutches[:"#{name}"].call(@collection)
end

#respond_to_missing?(name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/chewy/index/crutch.rb', line 24

def respond_to_missing?(name, include_private = false)
  @index._crutches.key?(name) || super
end