Class: Haipa::Links
- Inherits:
-
Object
- Object
- Haipa::Links
- Extended by:
- Forwardable
- Defined in:
- lib/haipa/links.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
(also: #to_hash)
readonly
Returns the value of attribute data.
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
Instance Method Summary collapse
-
#initialize(resource, data) ⇒ Links
constructor
A new instance of Links.
- #method_missing(name, *args, &block) ⇒ Object
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) = args.last.is_a?(::Hash) ? args.pop : {} href = template.().to_s end Resource.new(resource.api, href) else super end end |
Instance Attribute Details
#data ⇒ Object (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 |
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
5 6 7 |
# File 'lib/haipa/links.rb', line 5 def resource @resource end |