Class: RoadForest::PathProvider
- Inherits:
-
Object
- Object
- RoadForest::PathProvider
- Defined in:
- lib/roadforest/application/path-provider.rb
Instance Method Summary collapse
- #each_name_and_route(&block) ⇒ Object
- #find_route(&block) ⇒ Object
-
#initialize(route_name, dispatcher) ⇒ PathProvider
constructor
A new instance of PathProvider.
- #interface_for(name, vars = nil) ⇒ Object
-
#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.
- #pattern_for(name, vals = nil, extra = nil) ⇒ Object
- #request_for(name, vars = nil) ⇒ Object
- #route_for_name(name, params = nil) ⇒ Object
- #services ⇒ Object
- #url_for(route_name, params = nil) ⇒ Object
Constructor Details
#initialize(route_name, dispatcher) ⇒ PathProvider
Returns a new instance of PathProvider.
3 4 5 6 |
# File 'lib/roadforest/application/path-provider.rb', line 3 def initialize(route_name, dispatcher) @route_name = route_name @dispatcher = dispatcher end |
Instance Method Details
#each_name_and_route(&block) ⇒ Object
38 39 40 |
# 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) ⇒ Object
34 35 36 |
# File 'lib/roadforest/application/path-provider.rb', line 34 def find_route(&block) @dispatcher.find_route(&block) end |
#interface_for(name, vars = nil) ⇒ Object
52 53 54 55 56 |
# 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) ⇒ String
Get the URL to the given resource, with optional variables to be used for bindings in the path spec.
22 23 24 25 26 |
# 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) ⇒ Object
28 29 30 31 32 |
# 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) ⇒ Object
46 47 48 49 50 |
# 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) ⇒ Object
12 13 14 |
# 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 ⇒ Object
8 9 10 |
# File 'lib/roadforest/application/path-provider.rb', line 8 def services @dispatcher.services end |
#url_for(route_name, params = nil) ⇒ Object
42 43 44 |
# 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 |