class MongoMapper::Plugins::Associations::OneEmbeddedPolymorphicProxy

Public Instance Methods

replace(value) click to toggle source
# File lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb, line 6
def replace(value)
  @value = value.respond_to?(:attributes) ? value.attributes.merge(association.type_key_name => value.class.name) : value
  reset
end

Protected Instance Methods

find_target() click to toggle source
# File lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb, line 13
def find_target
  if @value
    child = polymorphic_class(@value).load(@value, true)
    assign_references(child)
    child
  end
end
polymorphic_class(doc) click to toggle source
# File lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb, line 21
def polymorphic_class(doc)
  if class_name = doc[association.type_key_name]
    class_name.constantize
  else
    klass
  end
end