Class: MongoMapper::Associations::ManyDocumentsProxy
- Inherits:
-
Proxy
- Object
- Proxy
- MongoMapper::Associations::ManyDocumentsProxy
show all
- Includes:
- Finders
- Defined in:
- lib/mongo_mapper/associations/many_documents_proxy.rb
Instance Attribute Summary
Attributes inherited from Proxy
#association, #owner
Instance Method Summary
collapse
Methods included from Finders
#dynamic_find
Methods inherited from Proxy
#initialize, #inspect, #nil?, #reload_target, #reset, #respond_to?, #send
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 89
def method_missing(method, *args)
finder = DynamicFinder.new(method)
if finder.found?
dynamic_find(finder, args)
else
super
end
end
|
Instance Method Details
#<<(*docs) ⇒ Object
Also known as:
push, concat
45
46
47
48
49
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 45
def <<(*docs)
ensure_owner_saved
flatten_deeper(docs).each { |doc| apply_scope(doc).save }
reset
end
|
#all(options = {}) ⇒ Object
23
24
25
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 23
def all(options={})
klass.all(scoped_options(options))
end
|
#build(attrs = {}) ⇒ Object
53
54
55
56
57
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 53
def build(attrs={})
doc = klass.new(attrs)
apply_scope(doc)
doc
end
|
#count(options = {}) ⇒ Object
35
36
37
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 35
def count(options={})
klass.count(scoped_options(options))
end
|
#create(attrs = {}) ⇒ Object
59
60
61
62
63
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 59
def create(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save
doc
end
|
#create!(attrs = {}) ⇒ Object
65
66
67
68
69
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 65
def create!(attrs={})
doc = klass.new(attrs)
apply_scope(doc).save!
doc
end
|
#delete_all(options = {}) ⇒ Object
76
77
78
79
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 76
def delete_all(options={})
klass.delete_all(options.merge(scoped_conditions))
reset
end
|
#destroy_all(options = {}) ⇒ Object
71
72
73
74
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 71
def destroy_all(options={})
all(options).map(&:destroy)
reset
end
|
#find(*args) ⇒ Object
9
10
11
12
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 9
def find(*args)
options = args.
klass.find(*args << scoped_options(options))
end
|
#find!(*args) ⇒ Object
14
15
16
17
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 14
def find!(*args)
options = args.
klass.find!(*args << scoped_options(options))
end
|
#first(options = {}) ⇒ Object
27
28
29
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 27
def first(options={})
klass.first(scoped_options(options))
end
|
#last(options = {}) ⇒ Object
31
32
33
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 31
def last(options={})
klass.last(scoped_options(options))
end
|
81
82
83
84
85
86
87
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 81
def nullify
criteria = FinderOptions.new(klass, scoped_conditions).criteria
all(criteria).each do |doc|
doc.update_attributes(self.foreign_key => nil)
end
reset
end
|
#paginate(options) ⇒ Object
19
20
21
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 19
def paginate(options)
klass.paginate(scoped_options(options))
end
|
#replace(docs) ⇒ Object
39
40
41
42
43
|
# File 'lib/mongo_mapper/associations/many_documents_proxy.rb', line 39
def replace(docs)
@target.map(&:destroy) if load_target
docs.each { |doc| apply_scope(doc).save }
reset
end
|