Class: Routemaster::Responses::HateoasResponse
- Inherits:
-
Object
- Object
- Routemaster::Responses::HateoasResponse
show all
- Extended by:
- Forwardable
- Defined in:
- lib/routemaster/responses/hateoas_response.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
_compile_method
Constructor Details
#initialize(response, client: nil) ⇒ HateoasResponse
13
14
15
16
|
# File 'lib/routemaster/responses/hateoas_response.rb', line 13
def initialize(response, client: nil)
@response = response
@client = client || Routemaster::APIClient.new(response_class: self.class)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/routemaster/responses/hateoas_response.rb', line 18
def method_missing(m, *args, &block)
method_name = m.to_s
normalized_method_name = method_name == '_self' ? 'self' : method_name
if _links.keys.include?(normalized_method_name)
unless respond_to?(method_name)
resource = Resources::RestResource.new(_links[normalized_method_name]['href'], client: @client)
define_singleton_method(method_name) { resource }
public_send method_name
end
else
super
end
end
|
Instance Attribute Details
#response ⇒ Object
Returns the value of attribute response.
10
11
12
|
# File 'lib/routemaster/responses/hateoas_response.rb', line 10
def response
@response
end
|
Instance Method Details
#body_without_links ⇒ Object
33
34
35
|
# File 'lib/routemaster/responses/hateoas_response.rb', line 33
def body_without_links
body.reject { |key, _| ['_links'].include?(key) }
end
|
#has?(link) ⇒ Boolean
37
38
39
|
# File 'lib/routemaster/responses/hateoas_response.rb', line 37
def has?(link)
_links.has_key?(link.to_s)
end
|