Class: JsonApiClient::Relationships::TopLevelRelations
- Inherits:
-
Object
- Object
- JsonApiClient::Relationships::TopLevelRelations
- Defined in:
- lib/json_api_client/relationships/top_level_relations.rb
Instance Attribute Summary collapse
-
#record_class ⇒ Object
readonly
Returns the value of attribute record_class.
-
#relations ⇒ Object
readonly
Returns the value of attribute relations.
Instance Method Summary collapse
- #fetch_relation(relation_name) ⇒ Object
-
#initialize(record_class, relations) ⇒ TopLevelRelations
constructor
A new instance of TopLevelRelations.
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(record_class, relations) ⇒ TopLevelRelations
Returns a new instance of TopLevelRelations.
7 8 9 10 |
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 7 def initialize(record_class, relations) @relations = relations @record_class = record_class end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 16 def method_missing(method, *args) if respond_to_missing?(method) fetch_relation(method) else super end end |
Instance Attribute Details
#record_class ⇒ Object (readonly)
Returns the value of attribute record_class.
5 6 7 |
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 5 def record_class @record_class end |
#relations ⇒ Object (readonly)
Returns the value of attribute relations.
5 6 7 |
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 5 def relations @relations end |
Instance Method Details
#fetch_relation(relation_name) ⇒ Object
24 25 26 27 |
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 24 def fetch_relation(relation_name) link_definition = relations.fetch(relation_name.to_s) record_class.requestor.linked(link_definition) end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
12 13 14 |
# File 'lib/json_api_client/relationships/top_level_relations.rb', line 12 def respond_to_missing?(method, include_private = false) relations.has_key?(method.to_s) || super end |