Class: Hactor::HAL::Link

Inherits:
OpenStruct
  • Object
show all
Defined in:
lib/hactor/hal/link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(obj, options) ⇒ Link

Returns a new instance of Link.



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

def initialize(obj, options)
  @href = obj['href']
  @rel = options.fetch(:rel)
  @parent_resource = options.fetch(:context)
  @template_class = options[:template_class] || Addressable::Template
  super(obj)
end

Instance Attribute Details

#parent_resourceObject (readonly)

Returns the value of attribute parent_resource.



7
8
9
# File 'lib/hactor/hal/link.rb', line 7

def parent_resource
  @parent_resource
end

#relObject (readonly)

Returns the value of attribute rel.



7
8
9
# File 'lib/hactor/hal/link.rb', line 7

def rel
  @rel
end

#template_classObject (readonly)

Returns the value of attribute template_class.



7
8
9
# File 'lib/hactor/hal/link.rb', line 7

def template_class
  @template_class
end

Instance Method Details

#href(variables = nil) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/hactor/hal/link.rb', line 17

def href(variables=nil)
  if templated?
    variables ||= {}
    template_class.new(@href).expand(variables).to_s
  else
    @href
  end
end

#templated?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/hactor/hal/link.rb', line 26

def templated?
  !!templated
end