Sha256: e4f7cdc06044e7260bfd479bcee0ab034b39a6f882b3a4c6e39b52dfd95ce32c

Contents?: true

Size: 799 Bytes

Versions: 5

Compression:

Stored size: 799 Bytes

Contents

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

        protected
          def find_target
            (@_values || []).map do |hash|
              child = polymorphic_class(hash).load(hash)
              assign_references(child)
              child
            end
          end

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

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
drogus-mongo_mapper-0.6.10 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.9 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.8 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.5 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.4 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb