Sha256: b80fe494936b10ee55224fb53fc3402d6cd41fb3e50ab724534844a733f12e0b

Contents?: true

Size: 793 Bytes

Versions: 19

Compression:

Stored size: 793 Bytes

Contents

module MongoMapper
  module Associations
    class ManyEmbeddedPolymorphicProxy < Proxy
      def replace(v)
        @_values = v.map do |doc_or_hash|
          if doc_or_hash.kind_of?(EmbeddedDocument)
            doc = doc_or_hash
            {@association.type_key_name => doc.class.name}.merge(doc.attributes)
          else
            doc_or_hash
          end
        end
        
        reset
      end

      protected
        def find_target
          (@_values || []).map do |hash|
            polymorphic_class(hash).new(hash)
          end
        end
        
        def polymorphic_class(doc)
          if class_name = doc[@association.type_key_name]
            class_name.constantize
          else
            @association.klass
          end
        end
    end
  end
end

Version data entries

19 entries across 19 versions & 5 rubygems

Version Path
mongo_mapper-0.6.6 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2009.12.4 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
danielharan-mongo_mapper-0.6.5 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.6.5 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
webbynode-mongo_mapper-0.6.4 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.6.4 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.6.3 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.6.2 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.6.1 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2009.11.18 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.6.0 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2009.11.8 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2009.11.6 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.8.2 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
djsun-mongo_mapper-0.5.8.1 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2009.11.2 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-unstable-2009.10.31 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.5.8 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb
mongo_mapper-0.5.7 lib/mongo_mapper/associations/many_embedded_polymorphic_proxy.rb