Class: ShafClient::BaseResource
- Inherits:
-
Object
- Object
- ShafClient::BaseResource
show all
- Defined in:
- lib/shaf_client/base_resource.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of BaseResource.
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/shaf_client/base_resource.rb', line 9
def initialize(payload)
@payload =
if payload&.is_a? String
JSON.parse(payload)
else
payload
end
parse
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
95
96
97
98
99
100
101
|
# File 'lib/shaf_client/base_resource.rb', line 95
def method_missing(method_name, *args, &block)
if attributes.key?(method_name)
attribute(method_name)
else
super
end
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
7
8
9
|
# File 'lib/shaf_client/base_resource.rb', line 7
def attributes
@attributes
end
|
#curies ⇒ Object
Returns the value of attribute curies.
7
8
9
|
# File 'lib/shaf_client/base_resource.rb', line 7
def curies
@curies
end
|
#embedded_resources ⇒ Object
Returns the value of attribute embedded_resources.
7
8
9
|
# File 'lib/shaf_client/base_resource.rb', line 7
def embedded_resources
@embedded_resources
end
|
#links ⇒ Object
Returns the value of attribute links.
7
8
9
|
# File 'lib/shaf_client/base_resource.rb', line 7
def links
@links
end
|
Instance Method Details
#[](key) ⇒ Object
43
44
45
|
# File 'lib/shaf_client/base_resource.rb', line 43
def [](key)
attributes[key]
end
|
#actions ⇒ Object
47
48
49
|
# File 'lib/shaf_client/base_resource.rb', line 47
def actions
links.keys
end
|
#attribute(key) ⇒ Object
27
28
29
|
# File 'lib/shaf_client/base_resource.rb', line 27
def attribute(key)
attributes.fetch(key.to_sym)
end
|
#curie(rel) ⇒ Object
35
36
37
|
# File 'lib/shaf_client/base_resource.rb', line 35
def curie(rel)
curies.fetch(rel.to_sym)
end
|
#embedded(rel) ⇒ Object
39
40
41
|
# File 'lib/shaf_client/base_resource.rb', line 39
def embedded(rel)
embedded_resources.fetch(rel.to_sym)
end
|
#link(rel) ⇒ Object
31
32
33
|
# File 'lib/shaf_client/base_resource.rb', line 31
def link(rel)
links.fetch(rel.to_sym)
end
|
#to_s ⇒ Object
20
21
22
23
24
25
|
# File 'lib/shaf_client/base_resource.rb', line 20
def to_s
attributes
.merge(_links: transform_values_to_s(links))
.merge(_embedded: transform_values_to_s(embedded_resources))
.to_s
end
|