Class: Hactor::HAL::Resource
- Inherits:
-
Object
- Object
- Hactor::HAL::Resource
- Extended by:
- Forwardable
- Defined in:
- lib/hactor/hal/resource.rb
Constant Summary collapse
- RESERVED_PROPERTIES =
['_links', '_embedded']
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#embedded_collection_class ⇒ Object
Returns the value of attribute embedded_collection_class.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#link_collection_class ⇒ Object
Returns the value of attribute link_collection_class.
-
#rel ⇒ Object
readonly
Returns the value of attribute rel.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
- #embedded_resource(rel) ⇒ Object
- #embedded_resources ⇒ Object
- #follow(rel, options = {}) ⇒ Object
-
#initialize(state, options) ⇒ Resource
constructor
A new instance of Resource.
- #link(rel, options = {}) ⇒ Object
- #links ⇒ Object
- #properties ⇒ Object
- #traverse(rel, options = {}) ⇒ Object
Constructor Details
#initialize(state, options) ⇒ Resource
Returns a new instance of Resource.
17 18 19 20 21 |
# File 'lib/hactor/hal/resource.rb', line 17 def initialize(state, ) @rel = .fetch(:rel) @context = .fetch(:context) @state = state end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
12 13 14 |
# File 'lib/hactor/hal/resource.rb', line 12 def context @context end |
#embedded_collection_class ⇒ Object
Returns the value of attribute embedded_collection_class.
13 14 15 |
# File 'lib/hactor/hal/resource.rb', line 13 def @embedded_collection_class end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
12 13 14 |
# File 'lib/hactor/hal/resource.rb', line 12 def http_client @http_client end |
#link_collection_class ⇒ Object
Returns the value of attribute link_collection_class.
13 14 15 |
# File 'lib/hactor/hal/resource.rb', line 13 def link_collection_class @link_collection_class end |
#rel ⇒ Object (readonly)
Returns the value of attribute rel.
12 13 14 |
# File 'lib/hactor/hal/resource.rb', line 12 def rel @rel end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
12 13 14 |
# File 'lib/hactor/hal/resource.rb', line 12 def state @state end |
Instance Method Details
#embedded_resource(rel) ⇒ Object
46 47 48 |
# File 'lib/hactor/hal/resource.rb', line 46 def (rel) .find(rel) end |
#embedded_resources ⇒ Object
50 51 52 53 |
# File 'lib/hactor/hal/resource.rb', line 50 def @embedded_resources ||= .new state['_embedded'], parent: self end |
#follow(rel, options = {}) ⇒ Object
23 24 25 |
# File 'lib/hactor/hal/resource.rb', line 23 def follow(rel, ={}) http_client.follow link(rel), () end |
#link(rel, options = {}) ⇒ Object
37 38 39 |
# File 'lib/hactor/hal/resource.rb', line 37 def link(rel, ={}) links.find(rel) end |
#links ⇒ Object
41 42 43 44 |
# File 'lib/hactor/hal/resource.rb', line 41 def links @links ||= link_collection_class.new state['_links'], parent: self end |
#properties ⇒ Object
31 32 33 34 35 |
# File 'lib/hactor/hal/resource.rb', line 31 def properties @properties ||= state.reject { |k,v| RESERVED_PROPERTIES.include? k } end |
#traverse(rel, options = {}) ⇒ Object
27 28 29 |
# File 'lib/hactor/hal/resource.rb', line 27 def traverse(rel, ={}) http_client.traverse link(rel), () end |