Class: Hactor::HAL::Document

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/hactor/hal/document.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(body, options = {}) ⇒ Document

Returns a new instance of Document.



10
11
12
13
14
# File 'lib/hactor/hal/document.rb', line 10

def initialize(body, options={})
  @resource_class = options.fetch(:resource_class) { Resource }
  @body = JSON.parse(body)
  super(root_resource)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/hactor/hal/document.rb', line 8

def body
  @body
end

#resource_classObject (readonly)

Returns the value of attribute resource_class.



8
9
10
# File 'lib/hactor/hal/document.rb', line 8

def resource_class
  @resource_class
end

Instance Method Details

#root_resourceObject



16
17
18
# File 'lib/hactor/hal/document.rb', line 16

def root_resource
  @root_resource ||= resource_class.new(body)
end