Class: Hanami::Router::MountedPath
- Inherits:
-
Object
- Object
- Hanami::Router::MountedPath
- Defined in:
- lib/hanami/router/mounted_path.rb
Overview
Instance Method Summary collapse
- #endpoint_and_params(env) ⇒ Object
-
#initialize(prefix, app) ⇒ MountedPath
constructor
A new instance of MountedPath.
Constructor Details
#initialize(prefix, app) ⇒ MountedPath
Returns a new instance of MountedPath.
6 7 8 9 |
# File 'lib/hanami/router/mounted_path.rb', line 6 def initialize(prefix, app) @prefix = prefix @app = app end |
Instance Method Details
#endpoint_and_params(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/hanami/router/mounted_path.rb', line 11 def endpoint_and_params(env) return [] unless (match = @prefix.peek_match(env[::Rack::PATH_INFO])) if @prefix.to_s == "/" env[::Rack::SCRIPT_NAME] = EMPTY_STRING else env[::Rack::SCRIPT_NAME] = env[::Rack::SCRIPT_NAME].to_s + @prefix.to_s env[::Rack::PATH_INFO] = env[::Rack::PATH_INFO].sub(@prefix.to_s, EMPTY_STRING) env[::Rack::PATH_INFO] = DEFAULT_PREFIX if env[::Rack::PATH_INFO] == EMPTY_STRING end [@app, match.named_captures] end |