Module: Sidewalk::AppUri

Defined in:
lib/sidewalk/app_uri.rb

Overview

URI relative to the root of the application.

For example, if your app lives at ‘www.example.com/foo’, AppUri.new(‘/bar’).to_s will reutrn ‘www.example.com/foo/bar’.

Not a real URI subclass, as URI subclasses by protocol, and this might return a URI::HTTP or URI::HTTPS subclass.

Class Method Summary collapse

Class Method Details

.new(path, query = {}) ⇒ Object

Create a URI relative to the application.

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.

Parameters:

  • path (String)

    is the path relative to the root of the application.

  • query (Hash) (defaults to: {})

    is a Hash of key-value query data.



23
24
25
26
27
28
29
30
31
# File 'lib/sidewalk/app_uri.rb', line 23

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.root_uri

  Sidewalk::RootedUri.new(uri, path, query)
end