Class: PMP::Link
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- PMP::Link
show all
- Includes:
- Parser
- Defined in:
- lib/pmp/link.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Parser
#extract_attributes, #extract_links, #parse, #parse_attributes, #parse_href, #parse_items, #parse_link, #parse_links, #parse_links_list, #parse_version
Methods included from Utils
#to_json_key_name, #to_ruby_safe_name
Constructor Details
#initialize(link = {}, parent = nil) ⇒ Link
28
29
30
31
32
33
34
35
|
# File 'lib/pmp/link.rb', line 28
def initialize(link={}, parent=nil)
super()
self.parent = parent || link.delete('parent')
self.params = link.delete('params') || {}
parse_attributes(link)
[:href, :href_template, :method].each{|m| self.send("#{m}=", nil) unless respond_to?(m)}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/pmp/link.rb', line 68
def method_missing(method, *args)
method_last = method.to_s.last
if method_last == '='
super
else
self.retrieve.send(method, *args)
end
end
|
Instance Attribute Details
#params ⇒ Object
Returns the value of attribute params.
26
27
28
|
# File 'lib/pmp/link.rb', line 26
def params
@params
end
|
#parent ⇒ Object
Returns the value of attribute parent.
24
25
26
|
# File 'lib/pmp/link.rb', line 24
def parent
@parent
end
|
Instance Method Details
#as_json(options = {}) ⇒ Object
45
46
47
|
# File 'lib/pmp/link.rb', line 45
def as_json(options={})
end
|
#attributes_map ⇒ Object
62
63
64
65
66
|
# File 'lib/pmp/link.rb', line 62
def attributes_map
attrs = HashWithIndifferentAccess.new(marshal_dump)
attrs.delete(attrs[:href_template].blank? ? :href_template : :href)
attrs
end
|
#retrieve ⇒ Object
55
56
57
58
59
60
|
# File 'lib/pmp/link.rb', line 55
def retrieve
@doc ||= PMP::CollectionDocument.new(parent.options.merge(href: url, root: parent.root))
end
|
#url ⇒ Object
49
50
51
52
53
|
# File 'lib/pmp/link.rb', line 49
def url
URITemplate.new(href_template || href).expand(params)
end
|
#where(params = {}) ⇒ Object
41
42
43
|
# File 'lib/pmp/link.rb', line 41
def where(params={})
self.class.new(attributes_map.merge({'params'=>params}), parent)
end
|