Class: Chewy::Type::Crutch::Crutches

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

Instance Method Summary collapse

Constructor Details

#initialize(type, collection) ⇒ Crutches

Returns a new instance of Crutches.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/chewy/type/crutch.rb', line 12

def initialize(type, collection)
  @type = type
  @collection = collection
  @type._crutches.each_key do |name|
    singleton_class.class_eval <<-METHOD, __FILE__, __LINE__ + 1
      def #{name}
        @#{name} ||= @type._crutches[:#{name}].call @collection
      end
    METHOD
  end
end