Class: MongoMapper::Plugins::Associations::Collection

Inherits:
Proxy
  • Object
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?

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

#[](val) ⇒ Object



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

#empty?Boolean

Returns:



27
28
29
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 27

def empty?
  to_a.empty?
end

#lengthObject



35
36
37
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 35

def length
  to_a.length
end

#readObject



44
45
46
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 44

def read
  self
end

#resetObject



39
40
41
42
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 39

def reset
  super
  target = []
end

#sizeObject



31
32
33
# File 'lib/mongo_mapper/plugins/associations/proxy/collection.rb', line 31

def size
  to_a.size
end

#to_aObject 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