Class: ApiResource::Associations::BelongsToRemoteObjectProxy

Inherits:
SingleObjectProxy show all
Defined in:
lib/api_resource/associations/belongs_to_remote_object_proxy.rb

Instance Attribute Summary collapse

Attributes inherited from AssociationProxy

#finder_opts, #klass, #owner, #remote_path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SingleObjectProxy

#==, #collection?, #eql?, #hash, #internal_object, #internal_object=, #serializable_hash

Methods inherited from AssociationProxy

#==, #expires_in, #includes, #internal_object, #load_resource_definition, #loaded?, #reload, #ttl

Constructor Details

#initialize(klass, owner, opts = {}) ⇒ BelongsToRemoteObjectProxy

constructor



15
16
17
18
19
20
21
22
23
24
# File 'lib/api_resource/associations/belongs_to_remote_object_proxy.rb', line 15

def initialize(klass, owner, opts = {})
  super

  @foreign_key = opts["foreign_key"] || @klass.to_s.foreign_key
  # now if we have an owner and a foreign key, we set 
  # the data up to load
  if key = owner.send(self.foreign_key)
    self.remote_path =  self.klass.element_path(key)
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class ApiResource::Associations::AssociationProxy

Instance Attribute Details

#foreign_keyObject (readonly)

Returns the value of attribute foreign_key.



5
6
7
# File 'lib/api_resource/associations/belongs_to_remote_object_proxy.rb', line 5

def foreign_key
  @foreign_key
end

Class Method Details

.define_association_as_attribute(klass, assoc_name, opts = {}) ⇒ Object

sets some defaults for the foreign key name for this association



9
10
11
12
# File 'lib/api_resource/associations/belongs_to_remote_object_proxy.rb', line 9

def self.define_association_as_attribute(klass, assoc_name, opts = {})
  opts["foreign_key"] = self.foreign_key_name(assoc_name)
  super(klass, assoc_name, opts)
end