Class: JsonApi::Resources::Relationship
- Inherits:
-
Object
- Object
- JsonApi::Resources::Relationship
- Defined in:
- lib/json_api_ruby/resources/relationships.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#included ⇒ Object
readonly
Determines whether the
dataattribute 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) ⇒ Relationship
constructor
A new instance of Relationship.
- #links ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, options) ⇒ Relationship
Returns a new instance of Relationship.
51 52 53 54 55 56 57 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 51 def initialize(name, ) @name = name @resources = [] @parent = .fetch(:parent_resource) @parent_model = parent._model @included = .fetch(:included, false) end |
Instance Attribute Details
#included ⇒ Object (readonly)
Determines whether the data attribute should be filled out and included
45 46 47 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 45 def included @included end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
46 47 48 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 46 def name @name end |
#parent ⇒ Object (readonly)
40 41 42 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 40 def parent @parent end |
#parent_model ⇒ Object (readonly)
Returns the value of attribute parent_model.
41 42 43 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 41 def parent_model @parent_model end |
#resources ⇒ Object (readonly)
The resource object that represents this relationship
49 50 51 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 49 def resources @resources end |
Instance Method Details
#included? ⇒ Boolean
59 60 61 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 59 def included? included == true end |
#links ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 69 def 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
63 64 65 66 67 |
# File 'lib/json_api_ruby/resources/relationships.rb', line 63 def to_hash return_hash = links return_hash.merge!(data) if included? return_hash end |