Class: JsonApiResource::Associations::BelongsTo

Inherits:
Base
  • Object
show all
Defined in:
lib/json_api_resource/associations/belongs_to.rb

Instance Attribute Summary

Attributes inherited from Base

#action, #key, #name, #root

Instance Method Summary collapse

Methods inherited from Base

#default_nil, #initialize, #klass, #opts, #post_process

Constructor Details

This class inherits a constructor from JsonApiResource::Associations::Base

Instance Method Details

#callable?(root_instance) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/json_api_resource/associations/belongs_to.rb', line 16

def callable?( root_instance )
  root_instance.send(key).present?
end

#default_actionObject



4
5
6
# File 'lib/json_api_resource/associations/belongs_to.rb', line 4

def default_action
  :find
end

#nil_defaultObject



20
21
22
# File 'lib/json_api_resource/associations/belongs_to.rb', line 20

def nil_default
  nil
end

#query(root_instance) ⇒ Object



12
13
14
# File 'lib/json_api_resource/associations/belongs_to.rb', line 12

def query( root_instance )
  root_instance.send key
end

#server_keyObject



8
9
10
# File 'lib/json_api_resource/associations/belongs_to.rb', line 8

def server_key
  "#{name}_id"
end

#typeObject



24
25
26
# File 'lib/json_api_resource/associations/belongs_to.rb', line 24

def type
  JsonApiResource::Associations::BELONGS_TO
end