Class: Haipa::Links

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/haipa/links.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, data) ⇒ Links



9
10
11
12
# File 'lib/haipa/links.rb', line 9

def initialize(resource, data)
  @data = data
  @resource = resource
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/haipa/links.rb', line 14

def method_missing(name, *args, &block)
  name = name.to_s
  if @data.has_key?(name)
    href = @data[name]['href']
    if @data[name]['templated'] == true
      template = Addressable::Template.new(href)
      options = args.last.is_a?(::Hash) ? args.pop : {}
      href = template.expand(options).to_s
    end
    Resource.new(resource.api, href)
  else
    super
  end
end

Instance Attribute Details

#dataObject (readonly) Also known as: to_hash

Returns the value of attribute data.



5
6
7
# File 'lib/haipa/links.rb', line 5

def data
  @data
end

#resourceObject (readonly)

Returns the value of attribute resource.



5
6
7
# File 'lib/haipa/links.rb', line 5

def resource
  @resource
end