Sha256: 61c99f48f17447831198bffd41a695a8aa37b736306a56436da3358aada0ec2b

Contents?: true

Size: 802 Bytes

Versions: 24

Compression:

Stored size: 802 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_root_document(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

24 entries across 24 versions & 3 rubygems

Version Path
novelys_mongo_mapper-0.6.12 lib/novelys_mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.11 lib/novelys_mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.3 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
novelys_mongo_mapper-0.6.10 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.2 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.2.1 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.31 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.30 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.29 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.28 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.27 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.26 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.25 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.22 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.21 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.20 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.19 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
jmonteiro-mongo_mapper-0.1.7 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.1.18 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
jmonteiro-mongo_mapper-0.1.6 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb