Class: MongoMapper::Associations::ManyEmbeddedProxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/mongomapper/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



31
32
33
34
35
36
37
38
39
# File 'lib/mongomapper/associations/many_embedded_proxy.rb', line 31

def <<(*docs)
  if load_target
    root = @owner._root_document || @owner
    docs.each do |doc|
      doc._root_document = root
      @target << doc
    end
  end
end

#build(opts = {}) ⇒ Object



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

def build(opts={})
  owner = @owner
  child = @association.klass.new(opts)
  assign_parent_reference(child)
  child._root_document = owner
  self << child
  child
end

#find(opts) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/mongomapper/associations/many_embedded_proxy.rb', line 18

def find(opts)
  case opts
  when :all
    self
  when String
    if load_target
      child = @target.detect {|item| item.id == opts}
      assign_parent_reference(child)
      child
    end
  end
end

#replace(v) ⇒ Object



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

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