class PMP::Link
Attributes
params[RW]
parent[RW]
Public Class Methods
new(link={}, parent=nil)
click to toggle source
Calls superclass method
# File lib/pmp/link.rb, line 27 def initialize(link={}, parent=nil) super() self.parent = parent || link.delete('parent') self.params = link.delete('params') || {} # puts "params: #{params.inspect}" parse_attributes(link) [:href, :href_template, :method].each{|m| self.send("#{m}=", nil) unless respond_to?(m)} end
Public Instance Methods
as_json(options={})
click to toggle source
# File lib/pmp/link.rb, line 44 def as_json(options={}) extract_attributes end
attributes_map()
click to toggle source
# File lib/pmp/link.rb, line 61 def attributes_map attrs = HashWithIndifferentAccess.new(marshal_dump) attrs.delete(attrs[:href_template].blank? ? :href_template : :href) attrs end
method_missing(method, *args)
click to toggle source
Calls superclass method
# File lib/pmp/link.rb, line 67 def method_missing(method, *args) # puts "mm: #{method}" # this is a method the link supports, call the link # if this is an assignment, assign to the link # if you want to assign to a linked doc(s), need to retrieve first method_last = method.to_s.last if method_last == '=' super else # puts "mm retrieve and send: #{method}" self.retrieve.send(method, *args) end end
retrieve()
click to toggle source
# File lib/pmp/link.rb, line 54 def retrieve # puts "retrieve method: #{method}" # puts "retrieve url: #{url}" # response = parent.request((method || 'get').to_sym, url) @doc ||= PMP::CollectionDocument.new(parent.options.merge(href: url, root: parent.root)) end
url()
click to toggle source
# File lib/pmp/link.rb, line 48 def url # puts "url href_template: #{href_template}" # puts "url href: #{href}" URITemplate.new(href_template || href).expand(params) end
where(params={})
click to toggle source
# File lib/pmp/link.rb, line 40 def where(params={}) self.class.new(attributes_map.merge({'params'=>params}), parent) end