Class: JSONAPI::Consumer::Linking::TopLevelLinks
- Inherits:
-
Object
- Object
- JSONAPI::Consumer::Linking::TopLevelLinks
- Defined in:
- lib/jsonapi/consumer/linking/top_level_links.rb
Instance Attribute Summary collapse
-
#links ⇒ Object
readonly
Returns the value of attribute links.
-
#record_class ⇒ Object
readonly
Returns the value of attribute record_class.
Instance Method Summary collapse
- #fetch_link(link_name) ⇒ Object
-
#initialize(record_class, links) ⇒ TopLevelLinks
constructor
A new instance of TopLevelLinks.
- #link_url_for(link_name) ⇒ Object
- #method_missing(method, *args) ⇒ Object
- #respond_to_missing?(method, include_private = false) ⇒ Boolean
Constructor Details
#initialize(record_class, links) ⇒ TopLevelLinks
Returns a new instance of TopLevelLinks.
7 8 9 10 |
# File 'lib/jsonapi/consumer/linking/top_level_links.rb', line 7 def initialize(record_class, links) @links = links @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/jsonapi/consumer/linking/top_level_links.rb', line 16 def method_missing(method, *args) if respond_to_missing?(method) fetch_link(method) else super end end |
Instance Attribute Details
#links ⇒ Object (readonly)
Returns the value of attribute links.
5 6 7 |
# File 'lib/jsonapi/consumer/linking/top_level_links.rb', line 5 def links @links end |
#record_class ⇒ Object (readonly)
Returns the value of attribute record_class.
5 6 7 |
# File 'lib/jsonapi/consumer/linking/top_level_links.rb', line 5 def record_class @record_class end |
Instance Method Details
#fetch_link(link_name) ⇒ Object
33 34 35 36 |
# File 'lib/jsonapi/consumer/linking/top_level_links.rb', line 33 def fetch_link(link_name) return unless respond_to_missing?(link_name) record_class.requestor.linked(link_url_for(link_name)) end |
#link_url_for(link_name) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/jsonapi/consumer/linking/top_level_links.rb', line 24 def link_url_for(link_name) link_definition = links.fetch(link_name.to_s) if link_definition.is_a?(Hash) link_definition["href"] else link_definition end end |
#respond_to_missing?(method, include_private = false) ⇒ Boolean
12 13 14 |
# File 'lib/jsonapi/consumer/linking/top_level_links.rb', line 12 def respond_to_missing?(method, include_private = false) links.has_key?(method.to_s) || super end |