Class: Hyperclient::LinkCollection
- Inherits:
-
Collection
- Object
- Collection
- Hyperclient::LinkCollection
- Defined in:
- lib/hyperclient/link_collection.rb
Overview
A wrapper class to easily acces the links in a Resource.
Instance Attribute Summary collapse
- #_curies ⇒ Object readonly
Instance Method Summary collapse
-
#build_curie(curie_hash, entry_point) ⇒ Object
private
private
Creates a curie from the response hash.
-
#build_link(name, link_or_links, curies, entry_point) ⇒ Object
private
private
Creates links from the response hash.
-
#initialize(collection, curies, entry_point) ⇒ LinkCollection
constructor
Initializes a LinkCollection.
Methods inherited from Collection
#[], #each, #fetch, #include?, #method_missing, #respond_to_missing?, #to_h, #to_s
Constructor Details
#initialize(collection, curies, entry_point) ⇒ LinkCollection
Initializes a LinkCollection.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/hyperclient/link_collection.rb', line 17 def initialize(collection, curies, entry_point) if collection && !collection.respond_to?(:collect) raise "Invalid response for LinkCollection. The response was: #{collection.inspect}" end @_curies = (curies || {}).reduce({}) do |hash, curie_hash| curie = build_curie(curie_hash, entry_point) hash.update(curie.name => curie) end @collection = (collection || {}).reduce({}) do |hash, (name, link)| hash.update(name => build_link(name, link, @_curies, entry_point)) end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Hyperclient::Collection
Instance Attribute Details
#_curies ⇒ Object (readonly)
10 11 12 |
# File 'lib/hyperclient/link_collection.rb', line 10 def _curies @_curies end |
Instance Method Details
#build_curie(curie_hash, entry_point) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a curie from the response hash.
60 61 62 |
# File 'lib/hyperclient/link_collection.rb', line 60 def build_curie(curie_hash, entry_point) Curie.new(curie_hash, entry_point) end |
#build_link(name, link_or_links, curies, entry_point) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates links from the response hash.
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/hyperclient/link_collection.rb', line 42 def build_link(name, link_or_links, curies, entry_point) return unless link_or_links if link_or_links.respond_to?(:to_ary) link_or_links.map do |link| build_link(name, link, curies, entry_point) end else Link.new(name, link_or_links, entry_point) end end |