Class: Hactor::HAL::Document

Inherits:
Delegator
  • Object
show all
Extended by:
Forwardable
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.



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

def initialize(body, options={})
  @response = options.fetch(:response)
  @resource_class = options[:resource_class] || Hactor::HAL::Resource
  body = '{}' if body == 'null'
  @body = JSON.parse(body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



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

def body
  @body
end

#resource_classObject (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

#responseObject (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_urlObject



30
31
32
# File 'lib/hactor/hal/document.rb', line 30

def base_url
  response.env[:url]
end

#root_resourceObject



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