Sha256: 17c671fa887be429ffa5477c9b784bb56991f5e70f008c09af686223cc79f28c

Contents?: true

Size: 775 Bytes

Versions: 7

Compression:

Stored size: 775 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)
              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

7 entries across 7 versions & 3 rubygems

Version Path
mongo_mapper-0.13.0.beta1 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.12.0 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
lookout-mongo_mapper-0.11.3 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.11.2 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
jamieorc-mongo_mapper-0.11.1.1 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.11.1 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb
mongo_mapper-0.11.0 lib/mongo_mapper/plugins/associations/one_embedded_polymorphic_proxy.rb