Class: Hactor::HAL::Document
- Inherits:
-
Delegator
- Object
- Delegator
- Hactor::HAL::Document
- Extended by:
- Forwardable
- Defined in:
- lib/hactor/hal/document.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#resource_class ⇒ Object
readonly
Returns the value of attribute resource_class.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
- #__getobj__ ⇒ Object
- #base_url ⇒ Object
-
#initialize(body, options = {}) ⇒ Document
constructor
A new instance of Document.
- #root_resource ⇒ Object
Constructor Details
#initialize(body, options = {}) ⇒ Document
Returns a new instance of Document.
15 16 17 18 19 20 |
# File 'lib/hactor/hal/document.rb', line 15 def initialize(body, ={}) @response = .fetch(:response) @resource_class = [:resource_class] || Hactor::HAL::Resource body = '{}' if body == 'null' @body = JSON.parse(body) end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
11 12 13 |
# File 'lib/hactor/hal/document.rb', line 11 def body @body end |
#resource_class ⇒ Object (readonly)
Returns the value of attribute resource_class.
11 12 13 |
# File 'lib/hactor/hal/document.rb', line 11 def resource_class @resource_class end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
11 12 13 |
# File 'lib/hactor/hal/document.rb', line 11 def response @response end |
Instance Method Details
#__getobj__ ⇒ Object
22 23 24 |
# File 'lib/hactor/hal/document.rb', line 22 def __getobj__ root_resource end |
#base_url ⇒ Object
30 31 32 |
# File 'lib/hactor/hal/document.rb', line 30 def base_url response.env[:url] end |
#root_resource ⇒ Object
26 27 28 |
# File 'lib/hactor/hal/document.rb', line 26 def root_resource @root_resource ||= resource_class.new(body, rel: 'self', context: self) end |