Module: LazyResource::Mapping::ClassMethods

Defined in:
lib/lazy_resource/mapping.rb

Instance Method Summary collapse

Instance Method Details

#load(objects) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/lazy_resource/mapping.rb', line 28

def load(objects)
  objects.fetched = true and return objects if objects.kind_of?(LazyResource::Mapping)

  if objects.is_a?(Array)
    Relation.new(self, :fetched => true).tap do |relation|
      relation.load(objects)
    end
  else
    if self.root_node_name && objects.key?(self.root_node_name.to_s)
      self.load(objects.delete(self.root_node_name.to_s)).tap do |obj|
        obj.other_attributes = objects
      end
    else
      self.new.load(objects)
    end
  end
end

#root_node_nameObject



24
25
26
# File 'lib/lazy_resource/mapping.rb', line 24

def root_node_name
  @root_node_name || LazyResource::Mapping.root_node_name
end

#root_node_name=(node) ⇒ Object



20
21
22
# File 'lib/lazy_resource/mapping.rb', line 20

def root_node_name=(node)
  @root_node_name = node
end