Class: RoadForest::PathProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/application/path-provider.rb

Instance Method Summary collapse

Constructor Details

#initialize(dispatcher) ⇒ PathProvider



3
4
5
# File 'lib/roadforest/application/path-provider.rb', line 3

def initialize(dispatcher)
  @dispatcher = dispatcher
end

Instance Method Details

#model_for(name, vars = nil) ⇒ Object



25
26
27
28
29
# File 'lib/roadforest/application/path-provider.rb', line 25

def model_for(name, vars = nil)
  route = @dispatcher.route_for_name(name)
  params = route.build_params(vars)
  route.resource.build_model(params)
end

#path_for(name, vars = nil) ⇒ String

Get the URL to the given resource, with optional variables to be used for bindings in the path spec.

Raises:

  • (RuntimeError)

    Raised if the resource is not routable.



13
14
15
16
17
# File 'lib/roadforest/application/path-provider.rb', line 13

def path_for(name, vars = nil)
  vars ||= {}
  route = @dispatcher.route_for_name(name)
  ::RDF::URI.parse(route.build_path(vars))
end

#request_for(name, vars = nil) ⇒ Object



19
20
21
22
23
# File 'lib/roadforest/application/path-provider.rb', line 19

def request_for(name, vars = nil)
  url = path_for(name, vars) #full url?

  Webmachine::Request.new(method, url, headers, body)
end