Class: Hyperclient::Link Private
- Inherits:
-
Object
- Object
- Hyperclient::Link
- Defined in:
- lib/hyperclient/link.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
The Link is used to let a Resource interact with the API.
Direct Known Subclasses
Instance Method Summary collapse
- #_delete ⇒ Object private
-
#_deprecation ⇒ Object
Returns the deprecation property of the Link.
-
#_expand(uri_variables = {}) ⇒ Object
Expands the Link when is templated with the given variables.
-
#_get ⇒ Object
Returns the Resource which the Link is pointing to.
- #_head ⇒ Object private
-
#_hreflang ⇒ Object
Returns the hreflang property of the Link.
-
#_name ⇒ Object
Returns the name property of the Link.
- #_options ⇒ Object private
- #_patch(params = {}) ⇒ Object private
- #_post(params = {}) ⇒ Object private
-
#_profile ⇒ Object
Returns the profile property of the Link.
- #_put(params = {}) ⇒ Object private
- #_resource ⇒ Object private
-
#_templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
-
#_title ⇒ Object
Returns the title property of the Link.
-
#_type ⇒ Object
Returns the type property of the Link.
-
#_uri_template ⇒ Object
private
private
Memoization for a URITemplate instance.
-
#_url ⇒ Object
Returns the url of the Link.
-
#_variables ⇒ Object
Returns an array of variables from the URITemplate.
-
#delegate_method(method, *args, &block) ⇒ Object
private
private
Delegate the method to the API if the resource cannot serve it.
- #http_method(method, body = nil) ⇒ Object private private
-
#initialize(key, link, entry_point, uri_variables = nil) ⇒ Link
constructor
Initializes a new Link.
- #inspect ⇒ Object private
-
#method_missing(method, *args, &block) ⇒ Object
private
private
Delegate the method further down the API if the resource cannot serve it.
-
#respond_to_missing?(method, _include_private = false) ⇒ Boolean
private
private
Accessory method to allow the link respond to the methods that will hit method_missing.
-
#to_ary ⇒ Object
private
private
avoid delegating to resource.
- #to_s ⇒ Object private
Constructor Details
#initialize(key, link, entry_point, uri_variables = nil) ⇒ Link
Initializes a new Link.
14 15 16 17 18 19 20 |
# File 'lib/hyperclient/link.rb', line 14 def initialize(key, link, entry_point, uri_variables = nil) @key = key @link = link @entry_point = entry_point @uri_variables = uri_variables @resource = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ 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.
Delegate the method further down the API if the resource cannot serve it.
127 128 129 130 131 132 133 134 |
# File 'lib/hyperclient/link.rb', line 127 def method_missing(method, *args, &block) if _resource.respond_to?(method.to_s) result = _resource.send(method, *args, &block) result.nil? ? delegate_method(method, *args, &block) : result else super end end |
Instance Method Details
#_delete ⇒ Object
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.
100 101 102 |
# File 'lib/hyperclient/link.rb', line 100 def _delete http_method(:delete) end |
#_deprecation ⇒ Object
Returns the deprecation property of the Link
64 65 66 |
# File 'lib/hyperclient/link.rb', line 64 def _deprecation @link['deprecation'] end |
#_expand(uri_variables = {}) ⇒ Object
Expands the Link when is templated with the given variables.
35 36 37 |
# File 'lib/hyperclient/link.rb', line 35 def (uri_variables = {}) self.class.new(@key, @link, @entry_point, uri_variables) end |
#_get ⇒ Object
Returns the Resource which the Link is pointing to.
88 89 90 |
# File 'lib/hyperclient/link.rb', line 88 def _get http_method(:get) end |
#_head ⇒ Object
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.
96 97 98 |
# File 'lib/hyperclient/link.rb', line 96 def _head http_method(:head) end |
#_hreflang ⇒ Object
Returns the hreflang property of the Link
79 80 81 |
# File 'lib/hyperclient/link.rb', line 79 def _hreflang @link['hreflang'] end |
#_name ⇒ Object
Returns the name property of the Link
59 60 61 |
# File 'lib/hyperclient/link.rb', line 59 def _name @link['name'] end |
#_options ⇒ Object
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.
92 93 94 |
# File 'lib/hyperclient/link.rb', line 92 def http_method(:options) end |
#_patch(params = {}) ⇒ Object
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.
112 113 114 |
# File 'lib/hyperclient/link.rb', line 112 def _patch(params = {}) http_method(:patch, params) end |
#_post(params = {}) ⇒ Object
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.
104 105 106 |
# File 'lib/hyperclient/link.rb', line 104 def _post(params = {}) http_method(:post, params) end |
#_profile ⇒ Object
Returns the profile property of the Link
69 70 71 |
# File 'lib/hyperclient/link.rb', line 69 def _profile @link['profile'] end |
#_put(params = {}) ⇒ Object
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.
108 109 110 |
# File 'lib/hyperclient/link.rb', line 108 def _put(params = {}) http_method(:put, params) end |
#_resource ⇒ Object
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.
83 84 85 |
# File 'lib/hyperclient/link.rb', line 83 def _resource @resource || _get end |
#_templated? ⇒ Boolean
Indicates if the link is an URITemplate or a regular URI.
26 27 28 |
# File 'lib/hyperclient/link.rb', line 26 def _templated? !!@link['templated'] end |
#_title ⇒ Object
Returns the title property of the Link
74 75 76 |
# File 'lib/hyperclient/link.rb', line 74 def _title @link['title'] end |
#_type ⇒ Object
Returns the type property of the Link
54 55 56 |
# File 'lib/hyperclient/link.rb', line 54 def _type @link['type'] end |
#_uri_template ⇒ 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.
Memoization for a URITemplate instance
167 168 169 |
# File 'lib/hyperclient/link.rb', line 167 def _uri_template @uri_template ||= Addressable::Template.new(@link['href']) end |
#_url ⇒ Object
Returns the url of the Link.
40 41 42 43 44 |
# File 'lib/hyperclient/link.rb', line 40 def _url return @link['href'] unless _templated? @url ||= _uri_template.(@uri_variables || {}).to_s end |
#_variables ⇒ Object
Returns an array of variables from the URITemplate.
49 50 51 |
# File 'lib/hyperclient/link.rb', line 49 def _variables _uri_template.variables end |
#delegate_method(method, *args, &block) ⇒ 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.
Delegate the method to the API if the resource cannot serve it.
This allows ‘api.posts` instead of `api._links.posts.embedded.posts`
139 140 141 142 143 144 145 146 |
# File 'lib/hyperclient/link.rb', line 139 def delegate_method(method, *args, &block) return unless @key && _resource.respond_to?(@key) @delegate ||= _resource.send(@key) return unless @delegate&.respond_to?(method.to_s) @delegate.send(method, *args, &block) end |
#http_method(method, body = nil) ⇒ 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.
171 172 173 174 175 176 |
# File 'lib/hyperclient/link.rb', line 171 def http_method(method, body = nil) @resource = begin response = @entry_point.connection.run_request(method, _url, body, nil) Resource.new(response.body, @entry_point, response) end end |
#inspect ⇒ Object
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.
116 117 118 |
# File 'lib/hyperclient/link.rb', line 116 def inspect "#<#{self.class.name}(#{@key}) #{@link}>" end |
#respond_to_missing?(method, _include_private = false) ⇒ Boolean (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.
Accessory method to allow the link respond to the methods that will hit method_missing.
150 151 152 153 154 155 156 |
# File 'lib/hyperclient/link.rb', line 150 def respond_to_missing?(method, _include_private = false) if @key && _resource.respond_to?(@key) && (delegate = _resource.send(@key)) && delegate.respond_to?(method.to_s) true else _resource.respond_to?(method.to_s) end end |
#to_ary ⇒ 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.
avoid delegating to resource
#to_ary is called for implicit array coercion (such as parallel assignment or Array#flatten). Returning nil tells Ruby that this record is not Array-like.
162 163 164 |
# File 'lib/hyperclient/link.rb', line 162 def to_ary nil end |
#to_s ⇒ Object
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.
120 121 122 |
# File 'lib/hyperclient/link.rb', line 120 def to_s _url end |