Sha256: 8ee199ddcaf16ccce94ae0e1f8c584761729876c09442d8967b737f212fdd85a
Contents?: true
Size: 833 Bytes
Versions: 2
Compression:
Stored size: 833 Bytes
Contents
module MongoMapper module Associations class ManyEmbeddedPolymorphicProxy < ArrayProxy 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 @target = nil reload_target 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jnunemaker-mongomapper-0.3.0 | lib/mongomapper/associations/many_embedded_polymorphic_proxy.rb |
jnunemaker-mongomapper-0.3.1 | lib/mongomapper/associations/many_embedded_polymorphic_proxy.rb |