Sha256: 0c5cc4e8972cff1937f87ceb12042587d1aa741c2fa2bac46cbb5ff93aea6518

Contents?: true

Size: 801 Bytes

Versions: 30

Compression:

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

30 entries across 30 versions & 6 rubygems

Version Path
pwnash-mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.7.6 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.7.5 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper_ign-0.7.4 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.7.4 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.7.3 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
numon-0.0.1 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.7.2 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.7.1 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.3.8 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.3.5 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.3.4 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.3.3 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-rails3-0.7.0.1 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.28 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.27 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.26 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.25 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.24 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.23 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb