class RoadForest::PathProvider

Public Class Methods

new(route_name, dispatcher) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 3
def initialize(route_name, dispatcher)
  @route_name = route_name
  @dispatcher = dispatcher
end

Public Instance Methods

each_name_and_route(&block) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 38
def each_name_and_route(&block)
  @dispatcher.each_name_and_route(&block)
end
find_route(&block) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 34
def find_route(&block)
  @dispatcher.find_route(&block)
end
interface_for(name, vars = nil) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 52
def interface_for(name, vars = nil)
  route = route_for_name(name)
  params = route.build_params(vars)
  route.resource.build_interface(params)
end
path_for(name, vars = nil) click to toggle source

Get the URL to the given resource, with optional variables to be used for bindings in the path spec. @param [Webmachine::Resource] resource the resource to link to @param [Hash] vars the values for the required path variables @raise [RuntimeError] Raised if the resource is not routable. @return [String] the URL

# File lib/roadforest/application/path-provider.rb, line 22
def path_for(name, vars = nil)
  vars ||= {}
  route = route_for_name(name)
  ::RDF::URI.parse(route.build_path(vars))
end
pattern_for(name, vals = nil, extra = nil) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 28
def pattern_for(name, vals = nil, extra = nil)
  vars ||= {}
  route = route_for_name(name)
  Addressable::URI.parse(services.canonical_host.to_s).join(route.build_pattern(vals, extra))
end
request_for(name, vars = nil) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 46
def request_for(name, vars = nil)
  url = path_for(name, vars) #full url?

  Webmachine::Request.new(method, url, headers, body)
end
route_for_name(name, params=nil) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 12
def route_for_name(name, params=nil)
  @dispatcher.mapped_route_for_name(@route_name, name, params)
end
services() click to toggle source
# File lib/roadforest/application/path-provider.rb, line 8
def services
  @dispatcher.services
end
url_for(route_name, params = nil) click to toggle source
# File lib/roadforest/application/path-provider.rb, line 42
def url_for(route_name, params = nil)
  ::RDF::URI.new(Addressable::URI.parse(services.canonical_host.to_s).join(path_for(route_name, params)))
end