Class: MongoMapper::Plugins::Associations::EmbeddedCollection

Inherits:
Collection show all
Defined in:
lib/mongo_mapper/plugins/associations/embedded_collection.rb

Instance Attribute Summary

Attributes inherited from Proxy

#association, #owner, #target

Instance Method Summary collapse

Methods inherited from Collection

#reset, #to_ary

Methods inherited from Proxy

#===, #blank?, #initialize, #inspect, #loaded, #loaded?, #nil?, #present?, #proxy_respond_to?, #reload, #replace, #reset, #respond_to?, #send

Constructor Details

This class inherits a constructor from MongoMapper::Plugins::Associations::Proxy

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class MongoMapper::Plugins::Associations::Proxy

Instance Method Details

#<<(*docs) ⇒ Object Also known as: push, concat



22
23
24
25
26
27
28
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 22

def <<(*docs)
  load_target
  docs.each do |doc|
    assign_references(doc)
    target << doc
  end
end

#build(attributes = {}) ⇒ Object



5
6
7
8
9
10
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 5

def build(attributes={})
  doc = klass.new(attributes)
  assign_references(doc)
  self << doc
  doc
end

#countObject



17
18
19
20
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 17

def count
  load_target
  target.size
end

#find(id) ⇒ Object



12
13
14
15
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 12

def find(id)
  load_target
  target.detect { |item| item.id.to_s == id || item.id == id }
end