Sha256: 109a9caa9ddb65afee0c598897319fbe959fc8558bdb8738bf7cec89e77b9795

Contents?: true

Size: 796 Bytes

Versions: 11

Compression:

Stored size: 796 Bytes

Contents

# encoding: UTF-8
module MongoMapper
  module Plugins
    module Associations
      class ManyEmbeddedPolymorphicProxy < EmbeddedCollection
        def replace(values)
          @_values = values.map do |v|
            v.respond_to?(:attributes) ? v.attributes.merge(association.type_key_name => v.class.name) : v
          end
          reset
        end

      protected

        def find_target
          (@_values || []).map do |hash|
            child = polymorphic_class(hash).load(hash, 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/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.16.0 lib/mongo_mapper/plugins/associations/proxy/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.6 lib/mongo_mapper/plugins/associations/proxy/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.5 lib/mongo_mapper/plugins/associations/proxy/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.4 lib/mongo_mapper/plugins/associations/proxy/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.3 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.2 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.1 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.15.0 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.14.0 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.14.0.rc1 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb