Module: Fire::Model::Parent::ClassMethods

Defined in:
lib/model/nested/parent.rb

Instance Method Summary collapse

Instance Method Details

#has_nested(nested_model) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/model/nested/parent.rb', line 12

def has_nested(nested_model)
  self.assigned_nested_models ||= []
  self.assigned_nested_models << nested_model

  folder = nested_model.nested_options.folder
  define_method "nested_#{folder}" do
    objects = self.class.down_levels(send(folder), nested_model.path_keys.count)
    objects.map{|x|
      full_data = x.merge(self.path_data)
      nested_model.new(full_data)
    }
  end

  define_method "add_to_#{folder}" do |object|
    nested_model.create(object.merge(self.path_data))
  end
end

#nested_modelsObject



30
31
32
# File 'lib/model/nested/parent.rb', line 30

def nested_models
  self.assigned_nested_models || []
end