Sha256: 5931d4b150b210de792fe8c5ab0b07a2c1f7a5829245f86a2ee49c2b7daa79fc

Contents?: true

Size: 819 Bytes

Versions: 75

Compression:

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

75 entries across 75 versions & 11 rubygems

Version Path
mongo_mapper-unstable-2010.08.19 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.18 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.17 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.16 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.15 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.14 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.13 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.12 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.11 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.10 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.09 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.8.3 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.08 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.06 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.05 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.04 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.03 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.02 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.08.01 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2010.07.31 lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb