Class: MongoMapper::Associations::ManyEmbeddedProxy
- Inherits:
-
Collection
- Object
- Proxy
- Collection
- MongoMapper::Associations::ManyEmbeddedProxy
- Defined in:
- lib/mongo_mapper/associations/many_embedded_proxy.rb
Instance Attribute Summary
Attributes inherited from Proxy
Instance Method Summary collapse
- #<<(*docs) ⇒ Object (also: #push, #concat)
- #build(attributes = {}) ⇒ Object
-
#find(id) ⇒ Object
TODO: test that both string and oid version work.
- #replace(values) ⇒ Object
Methods inherited from Collection
Methods inherited from Proxy
#===, #blank?, #initialize, #inspect, #loaded, #loaded?, #nil?, #present?, #proxy_respond_to?, #reload, #reset, #respond_to?, #send
Constructor Details
This class inherits a constructor from MongoMapper::Associations::Proxy
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class MongoMapper::Associations::Proxy
Instance Method Details
#<<(*docs) ⇒ Object Also known as: push, concat
24 25 26 27 28 29 30 |
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 24 def <<(*docs) load_target docs.each do |doc| assign_root_document(doc) target << doc end end |
#build(attributes = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 11 def build(attributes={}) doc = klass.new(attributes) assign_root_document(doc) self << doc doc end |
#find(id) ⇒ Object
TODO: test that both string and oid version work
19 20 21 22 |
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 19 def find(id) load_target target.detect { |item| item.id.to_s == id || item.id == id } end |
#replace(values) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 4 def replace(values) @_values = values.map do |v| v.kind_of?(EmbeddedDocument) ? v.attributes : v end reset end |