Sha256: e28bbbf9d1b4de4a50640ab3068fb1ba114bc2fd79990d09c9b1a968072852c7

Contents?: true

Size: 761 Bytes

Versions: 5

Compression:

Stored size: 761 Bytes

Contents

require 'ripple/associations/proxy'
require 'ripple/associations/one'
require 'ripple/associations/embedded'

module Ripple
  module Associations
    class OneEmbeddedProxy < Proxy
      include One
      include Embedded

      def replace(doc)
        @reflection.verify_type!(doc, @owner)
        @_doc = doc.respond_to?(:attributes_for_persistence) ? doc.attributes_for_persistence : doc
        assign_references(doc)

        if doc.is_a?(@reflection.klass)
          loaded
          @target = doc
        else
          reset
        end

        @_doc
      end

      protected
      def find_target
        return nil unless @_doc
        klass.instantiate(@_doc).tap do |doc|
          assign_references(doc)
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 4 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/associations/one_embedded_proxy.rb
better-ripple-1.0.0 lib/ripple/associations/one_embedded_proxy.rb
ripple-1.0.0.beta2 lib/ripple/associations/one_embedded_proxy.rb
seomoz-ripple-1.0.0.pre lib/ripple/associations/one_embedded_proxy.rb
ripple-1.0.0.beta lib/ripple/associations/one_embedded_proxy.rb