Class: MongoMapper::Plugins::Associations::Collection
- Inherits:
-
Proxy
- Object
- Proxy
- MongoMapper::Plugins::Associations::Collection
show all
- Includes:
- Enumerable
- Defined in:
- lib/mongo_mapper/plugins/associations/proxy/collection.rb
Instance Attribute Summary
Attributes inherited from Proxy
#association, #proxy_owner, #target
Instance Method Summary
collapse
Methods inherited from Proxy
define_proxy_method, #initialize, #inspect, #loaded, #loaded?, #proxy_method, #proxy_respond_to?, #reload, #replace, #respond_to?
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class MongoMapper::Plugins::Associations::Proxy
Instance Method Details
22
23
24
25
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 22
def [](val)
objs = to_a
objs ? objs[val] : nil
end
|
#each(&block) ⇒ Object
18
19
20
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 18
def each(&block)
to_a.each(&block)
end
|
27
28
29
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 27
def empty?
to_a.empty?
end
|
35
36
37
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 35
def length
to_a.length
end
|
44
45
46
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 44
def read
self
end
|
39
40
41
42
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 39
def reset
super
target = []
end
|
31
32
33
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 31
def size
to_a.size
end
|
#to_a ⇒ Object
Also known as:
to_ary
8
9
10
11
12
13
14
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 8
def to_a
load_target
target.is_a?(Array) ?
target :
Array(target)
end
|
#write(value) ⇒ Object
48
49
50
51
|
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 48
def write(value)
replace(value)
read
end
|