Sha256: f3c81cd6905a29f6413f8d5d71bc1a42461aed405f0f71258b6115a056616968

Contents?: true

Size: 649 Bytes

Versions: 2

Compression:

Stored size: 649 Bytes

Contents

require 'api_resource/associations/single_object_proxy'
module ApiResource
  module Associations
    class HasOneRemoteObjectProxy < SingleObjectProxy
      
      def initialize(klass, owner)
        super(klass, owner)
        
        # now if we have an owner and a foreign key, we set the data up to load
        self.remote_path = self.klass.collection_path(self.owner.class.to_s.foreign_key => self.owner.id)
      end

      protected
      
      def load(opts = {})
        data = self.klass.connection.get(self.build_load_path(opts))
        return nil if data.blank?
        return self.klass.new(data.first)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
api_resource-0.5.1 lib/api_resource/associations/has_one_remote_object_proxy.rb
api_resource-0.5.0 lib/api_resource/associations/has_one_remote_object_proxy.rb