Sha256: e3be9748d6fda3a36f233b991b3203f7c47a4deec34b6e159b8bf3abeee9f930

Contents?: true

Size: 824 Bytes

Versions: 6

Compression:

Stored size: 824 Bytes

Contents

# encoding: UTF-8
module MarkMapper
  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, true)
              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

6 entries across 6 versions & 1 rubygems

Version Path
mark_mapper-0.0.6 lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mark_mapper-0.0.5 lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mark_mapper-0.0.4 lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mark_mapper-0.0.3 lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mark_mapper-0.0.2 lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb
mark_mapper-0.0.1 lib/mark_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb