Class: MongoMapper::Associations::ManyEmbeddedProxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/mongo_mapper/associations/many_embedded_proxy.rb

Instance Attribute Summary

Attributes inherited from Proxy

#association, #owner

Instance Method Summary collapse

Methods inherited from Proxy

#initialize, #inspect, #nil?, #reload_target, #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



22
23
24
25
26
27
28
29
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 22

def <<(*docs)
  if load_target
    docs.each do |doc|
      assign_root_document(doc)
      @target << doc
    end
  end
end

#build(attributes = {}) ⇒ Object



9
10
11
12
13
14
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 9

def build(attributes={})
  doc = @association.klass.new(attributes)
  assign_root_document(doc)
  self << doc
  doc
end

#find(id) ⇒ Object

TODO: test that both string and oid version work



17
18
19
20
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 17

def find(id)
  load_target
  @target.detect { |item| item.id.to_s == id || item.id == id }
end

#replace(v) ⇒ Object



4
5
6
7
# File 'lib/mongo_mapper/associations/many_embedded_proxy.rb', line 4

def replace(v)
  @_values = v.map { |e| e.kind_of?(EmbeddedDocument) ? e.attributes : e }
  reset
end