Sha256: e93eab086c25a27648376d4b82b6d9acc5d563e0232f09d2aa169129c703d4f4

Contents?: true

Size: 745 Bytes

Versions: 11

Compression:

Stored size: 745 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Associations
      class OneEmbeddedPolymorphicProxy < OneEmbeddedProxy
        def replace(value)
          @value = value.respond_to?(:attributes) ? value.attributes.merge(association.type_key_name => value.class.name) : value
          reset
        end

      protected

        def find_target
          if @value
            child = polymorphic_class(@value).load(@value, true)
            assign_references(child)
            child
          end
        end

        def polymorphic_class(doc)
          if class_name = doc[association.type_key_name]
            class_name.constantize
          else
            klass
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mongo_mapper-0.17.0 lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.16.0 lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.6 lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.5 lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.4 lib/mongo_mapper/plugins/associations/proxy/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.3 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.2 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.1 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.0 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.14.0 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.14.0.rc1 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb