class MongoMapper::Plugins::Associations::OneEmbeddedProxy
Public Instance Methods
build(attributes={})
click to toggle source
# 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)
click to toggle source
# 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={})
click to toggle source
# File lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb, line 26 def save_to_collection(options={}) @target.persist(options) if @target end
Protected Instance Methods
assign_references(doc)
click to toggle source
# File lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb, line 40 def assign_references(doc) doc._parent_document = proxy_owner if doc end
find_target()
click to toggle source
# File lib/mongo_mapper/plugins/associations/proxy/one_embedded_proxy.rb, line 32 def find_target if @value klass.load(@value, true).tap do |child| assign_references(child) end end end