Class: JsonApi::Association
- Inherits:
-
Object
- Object
- JsonApi::Association
- Defined in:
- lib/json_api_ruby/association.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#explicit_resource_class ⇒ Object
readonly
Returns the value of attribute explicit_resource_class.
-
#included ⇒ Object
readonly
Determines whether the ‘data` attribute should be filled out and included.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#parent ⇒ Object
readonly
The resource object that “owns” this relationship.
-
#parent_model ⇒ Object
readonly
Returns the value of attribute parent_model.
-
#resources ⇒ Object
readonly
The resource object that represents this relationship.
Instance Method Summary collapse
- #included? ⇒ Boolean
-
#initialize(name, options) ⇒ Association
constructor
A new instance of Association.
- #relationship_links ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Association
Returns a new instance of Association.
24 25 26 27 28 29 30 31 |
# File 'lib/json_api_ruby/association.rb', line 24 def initialize(name, ) @name = name @resources = [] @parent = .fetch(:parent_resource) @parent_model = parent._model @included = .fetch(:included, JsonApi::Includes.new) @explicit_resource_class = .fetch(:explicit_resource_class) end |
Instance Attribute Details
#explicit_resource_class ⇒ Object (readonly)
Returns the value of attribute explicit_resource_class.
18 19 20 |
# File 'lib/json_api_ruby/association.rb', line 18 def explicit_resource_class @explicit_resource_class end |
#included ⇒ Object (readonly)
Determines whether the ‘data` attribute should be filled out and included
16 17 18 |
# File 'lib/json_api_ruby/association.rb', line 16 def included @included end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
17 18 19 |
# File 'lib/json_api_ruby/association.rb', line 17 def name @name end |
#parent ⇒ Object (readonly)
11 12 13 |
# File 'lib/json_api_ruby/association.rb', line 11 def parent @parent end |
#parent_model ⇒ Object (readonly)
Returns the value of attribute parent_model.
12 13 14 |
# File 'lib/json_api_ruby/association.rb', line 12 def parent_model @parent_model end |
#resources ⇒ Object (readonly)
The resource object that represents this relationship
22 23 24 |
# File 'lib/json_api_ruby/association.rb', line 22 def resources @resources end |
Instance Method Details
#included? ⇒ Boolean
33 34 35 |
# File 'lib/json_api_ruby/association.rb', line 33 def included? included.has_name?(@name) end |
#relationship_links ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/json_api_ruby/association.rb', line 44 def relationship_links { 'links' => { 'self' => JsonApi.configuration.base_url + parent.self_link_path + "/relationships/#{name}", 'related' => JsonApi.configuration.base_url + parent.self_link_path + "/#{name}" } } end |
#to_hash ⇒ Object
37 38 39 40 41 42 |
# File 'lib/json_api_ruby/association.rb', line 37 def to_hash return_hash = {} return_hash.merge!(relationship_links) if JsonApi.configuration.use_links return_hash.merge!(data) if included? return_hash end |