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_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(parent = PMP::CollectionDocument.new, link = {}) ⇒ Link
Returns a new instance of Link.
28
29
30
31
32
33
34
|
# File 'lib/pmp/link.rb', line 28
def initialize(parent=PMP::CollectionDocument.new, link={})
super()
self.parent = parent
self.params = link.delete('params') || {}
parse_attributes(link)
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/pmp/link.rb', line 72
def method_missing(method, *args)
if self.respond_to?(method)
self.send(method, *args)
elsif method.to_s.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 ⇒ Object
56
57
58
|
# File 'lib/pmp/link.rb', line 56
def as_json
end
|
#attributes ⇒ Object
48
49
50
|
# File 'lib/pmp/link.rb', line 48
def attributes
HashWithIndifferentAccess.new(marshal_dump)
end
|
#href ⇒ Object
36
37
38
|
# File 'lib/pmp/link.rb', line 36
def href
self[:href]
end
|
#href_template ⇒ Object
40
41
42
|
# File 'lib/pmp/link.rb', line 40
def href_template
self[:href_template]
end
|
#method ⇒ Object
44
45
46
|
# File 'lib/pmp/link.rb', line 44
def method
self[:method]
end
|
#retrieve ⇒ Object
66
67
68
69
70
|
# File 'lib/pmp/link.rb', line 66
def retrieve
parent.request((method || 'get').to_sym, url)
end
|
#url ⇒ Object
60
61
62
63
64
|
# File 'lib/pmp/link.rb', line 60
def url
URITemplate.new(href_template || href).expand(params)
end
|
#where(params = {}) ⇒ Object
52
53
54
|
# File 'lib/pmp/link.rb', line 52
def where(params={})
self.class.new(parent, attributes.merge({'params'=>params}))
end
|