Sha256: ce744839084ed3e5e9e2622dac998538f7fa68bf11fb4faf0bf11735f47093e4

Contents?: true

Size: 711 Bytes

Versions: 5

Compression:

Stored size: 711 Bytes

Contents

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

module Ripple
  module Associations
    class OneStoredKeyProxy < Proxy
      include One

      def replace(value)
        @reflection.verify_type!(value, owner)

        if value
          assign_key(value.key)
        else
          assign_key(nil)
        end

        @target = value
        loaded
      end

      protected

      def key
        @owner.send(key_name)
      end

      def assign_key(value)
        @owner.send("#{key_name}=", value)
      end

      def key_name
        "#{@reflection.name}_key"
      end

      def find_target
        return nil if key.blank?

        klass.find(key)
      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_stored_key_proxy.rb
better-ripple-1.0.0 lib/ripple/associations/one_stored_key_proxy.rb
ripple-1.0.0.beta2 lib/ripple/associations/one_stored_key_proxy.rb
seomoz-ripple-1.0.0.pre lib/ripple/associations/one_stored_key_proxy.rb
ripple-1.0.0.beta lib/ripple/associations/one_stored_key_proxy.rb