Module: Sidewalk::RelativeUri
- Defined in:
- lib/sidewalk/relative_uri.rb
Overview
URI relative to the current request.
For example, if your app lives at ‘www.example.com/foo’, the current request is to ‘/foo/bar’, RelativeUri.new(‘/baz’).to_s will return ‘www.example.com/foo/bar/baz’, whereas AppUri would give you ‘www.example.com/foo/baz’.
Existing query data is discarded.
Not a real class as the URI
hierarchy doesn’t lend itself to subclassing.
Class Method Summary collapse
-
.new(path, query = {}) ⇒ Object
Create a URI relative to the current request.
Class Method Details
.new(path, query = {}) ⇒ Object
Create a URI relative to the current request.
If this is called, it must have Controller#call in the call stack so that Controller.current works - otherwise it does not have enough information to construct the URI.
Query string data is discarded.
28 29 30 31 32 33 34 35 36 |
# File 'lib/sidewalk/relative_uri.rb', line 28 def self.new path, query = {} context = Sidewalk::Controller.current unless context raise ScriptError.new("Only valid when called by a controller") end uri = context.request.uri Sidewalk::RootedUri.new(uri, path, query) end |