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, #proxy_owner, #target
Instance Method Summary
collapse
Methods inherited from Collection
#include?, #reset, #to_ary
Methods inherited from Proxy
#as_json, #blank?, #initialize, #inspect, #loaded, #loaded?, #nil?, #present?, #proxy_respond_to?, #reload, #replace, #reset, #respond_to?, #send, #to_json
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
23
24
25
26
27
28
29
|
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 23
def <<(*docs)
load_target
docs.each do |doc|
assign_references(doc)
target << doc
end
end
|
#build(attributes = {}) ⇒ Object
6
7
8
9
10
11
|
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 6
def build(attributes={})
doc = klass.new(attributes)
assign_references(doc)
self << doc
doc
end
|
18
19
20
21
|
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 18
def count
load_target
target.size
end
|
13
14
15
16
|
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 13
def find(id)
load_target
target.detect { |item| item.id.to_s == id || item.id == id }
end
|
#save_to_collection(options = {}) ⇒ Object
33
34
35
|
# File 'lib/mongo_mapper/plugins/associations/embedded_collection.rb', line 33
def save_to_collection(options={})
@target.each { |doc| doc.persist(options) } if @target
end
|