class HyperResource::Link

Attributes

base_href[RW]
name[RW]
params[RW]
parent_resource[RW]
templated[RW]

Public Class Methods

new(resource=nil, link_spec={}) click to toggle source
# File lib/hyper_resource/link.rb, line 13
def initialize(resource=nil, link_spec={})
  self.parent_resource = resource || HyperResource.new
  self.base_href = link_spec['href']
  self.name = link_spec['name']
  self.templated = !!link_spec['templated']
  self.params    = link_spec['params'] || {}
end

Public Instance Methods

delete(*args) click to toggle source
# File lib/hyper_resource/link.rb, line 52
def delete(*args); self.resource.delete(*args) end
get(*args) click to toggle source

Delegate HTTP methods to the resource.

# File lib/hyper_resource/link.rb, line 48
def get(*args);    self.resource.get(*args)    end
href() click to toggle source

Returns this link's href, applying any URI template params.

# File lib/hyper_resource/link.rb, line 22
def href
  if self.templated?
    filtered_params = self.parent_resource.outgoing_uri_filter(params)
    URITemplate.new(self.base_href).expand(filtered_params)
  else
    self.base_href
  end
end
method_missing(method, *args, &block) click to toggle source

If we were called with a method we don't know, load this resource and pass the message along. This achieves implicit loading.

# File lib/hyper_resource/link.rb, line 56
def method_missing(method, *args, &block)
  self.get.send(method, *args, &block)
end
patch(*args) click to toggle source
# File lib/hyper_resource/link.rb, line 50
def patch(*args);  self.resource.patch(*args)  end
post(*args) click to toggle source
# File lib/hyper_resource/link.rb, line 49
def post(*args);   self.resource.post(*args)   end
put(*args) click to toggle source
# File lib/hyper_resource/link.rb, line 51
def put(*args);    self.resource.put(*args)    end
resource() click to toggle source

Returns a HyperResource representing this link

# File lib/hyper_resource/link.rb, line 43
def resource
  parent_resource._hr_new_from_link(self.href)
end
templated?() click to toggle source

Returns true if this link is templated.

# File lib/hyper_resource/link.rb, line 11
def templated?; templated end
where(params) click to toggle source

Returns a new scope with the given params; that is, returns a copy of itself with the given params applied.

# File lib/hyper_resource/link.rb, line 33
def where(params)
  params = Hash[ params.map{|(k,v)| [k.to_s, v]} ]
  self.class.new(self.parent_resource,
                 'href' => self.base_href,
                 'name' => self.name,
                 'templated' => self.templated,
                 'params' => self.params.merge(params))
end