Class: JsonApiClient::Associations::BaseAssociation
- Inherits:
-
Object
- Object
- JsonApiClient::Associations::BaseAssociation
- Defined in:
- lib/json_api_client/associations/base_association.rb
Direct Known Subclasses
JsonApiClient::Associations::BelongsTo::Association, HasMany::Association, HasOne::Association
Instance Attribute Summary collapse
-
#attr_name ⇒ Object
readonly
Returns the value of attribute attr_name.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #association_class ⇒ Object
- #data(url) ⇒ Object
- #from_result_set(result_set) ⇒ Object
-
#initialize(attr_name, klass, options = {}) ⇒ BaseAssociation
constructor
A new instance of BaseAssociation.
Constructor Details
#initialize(attr_name, klass, options = {}) ⇒ BaseAssociation
Returns a new instance of BaseAssociation.
5 6 7 8 9 |
# File 'lib/json_api_client/associations/base_association.rb', line 5 def initialize(attr_name, klass, = {}) @attr_name = attr_name @klass = klass @options = end |
Instance Attribute Details
#attr_name ⇒ Object (readonly)
Returns the value of attribute attr_name.
4 5 6 |
# File 'lib/json_api_client/associations/base_association.rb', line 4 def attr_name @attr_name end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
4 5 6 |
# File 'lib/json_api_client/associations/base_association.rb', line 4 def klass @klass end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/json_api_client/associations/base_association.rb', line 4 def @options end |
Instance Method Details
#association_class ⇒ Object
11 12 13 14 15 |
# File 'lib/json_api_client/associations/base_association.rb', line 11 def association_class @association_class ||= Utils.compute_type(klass, .fetch(:class_name) do attr_name.to_s.classify end) end |
#data(url) ⇒ Object
17 18 19 |
# File 'lib/json_api_client/associations/base_association.rb', line 17 def data(url) from_result_set(association_class.requestor.linked(url)) end |
#from_result_set(result_set) ⇒ Object
21 22 23 |
# File 'lib/json_api_client/associations/base_association.rb', line 21 def from_result_set(result_set) result_set.to_a end |