Sha256: 9d9d72b259241de3388a2b9be4965314f6f1513728e52b01ad916055136ca534

Contents?: true

Size: 909 Bytes

Versions: 3

Compression:

Stored size: 909 Bytes

Contents

require 'ripple/associations/proxy'
require 'ripple/associations/many'
require 'ripple/associations/embedded'

module Ripple
  module Associations
    class ManyEmbeddedProxy < Proxy
      include Many
      include Embedded

      def <<(docs)
        load_target
        docs = Array.wrap(docs)
        @reflection.verify_type!(docs, @owner)
        assign_references(docs)
        @target += docs
        self
      end

      def replace(docs)
        @reflection.verify_type!(docs, @owner)
        @_docs = docs.map { |doc| attrs = doc.respond_to?(:attributes_for_persistence) ? doc.attributes_for_persistence : doc }
        assign_references(docs)
        reset
        @_docs
      end

      protected
      def find_target
        (@_docs || []).map do |attrs|
          klass.instantiate(attrs).tap do |doc|
            assign_references(doc)
          end
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 3 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/associations/many_embedded_proxy.rb
better-ripple-1.0.0 lib/ripple/associations/many_embedded_proxy.rb
ripple-1.0.0.beta2 lib/ripple/associations/many_embedded_proxy.rb