Class: JsonApiClient::LinkDefinition
- Inherits:
-
Object
- Object
- JsonApiClient::LinkDefinition
- Defined in:
- lib/json_api_client/link_definition.rb
Instance Method Summary collapse
- #attribute_name_for(type) ⇒ Object
- #has_link?(type) ⇒ Boolean
-
#initialize(spec) ⇒ LinkDefinition
constructor
A new instance of LinkDefinition.
- #url_for(type, ids) ⇒ Object
Constructor Details
#initialize(spec) ⇒ LinkDefinition
Returns a new instance of LinkDefinition.
4 5 6 7 8 9 |
# File 'lib/json_api_client/link_definition.rb', line 4 def initialize(spec) @spec = {}.with_indifferent_access spec.each do |type, definition| @spec[type.split(".").last] = definition.merge({slurp: type}) end end |
Instance Method Details
#attribute_name_for(type) ⇒ Object
15 16 17 |
# File 'lib/json_api_client/link_definition.rb', line 15 def attribute_name_for(type) @spec.fetch(type).fetch("type") end |
#has_link?(type) ⇒ Boolean
11 12 13 |
# File 'lib/json_api_client/link_definition.rb', line 11 def has_link?(type) @spec.has_key?(type) end |
#url_for(type, ids) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/json_api_client/link_definition.rb', line 19 def url_for(type, ids) definition = @spec.fetch(type) href = definition.fetch("href") slurp = definition.fetch("slurp") href.gsub("{#{slurp}}", Array(ids).join(",")) end |