Class: MongoMapper::Plugins::Associations::OneEmbeddedProxy

Inherits:
Proxy
  • Object
show all
Defined in:
lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb

Direct Known Subclasses

OneEmbeddedPolymorphicProxy

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?, #read, #reload, #reset, #respond_to?, #write

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

#build(attributes = {}) ⇒ Object



6
7
8
9
10
11
# File 'lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb', line 6

def build(attributes={})
  @target = klass.new(attributes)
  assign_references(@target)
  loaded
  @target
end

#replace(doc) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb', line 13

def replace(doc)
  if doc.instance_of?(klass)
    @target = doc
  elsif doc.respond_to?(:attributes)
    @target = klass.load(doc.attributes, true)
  else
    @target = klass.load(doc, true)
  end
  assign_references(@target)
  loaded
  @target
end

#save_to_collection(options = {}) ⇒ Object



26
27
28
# File 'lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb', line 26

def save_to_collection(options={})
  @target.persist(options) if @target
end