Class: Hanami::Router::MountedPath

Inherits:
Object
  • Object
show all
Defined in:
gems/gems/hanami-router-2.1.0/lib/hanami/router/mounted_path.rb

Overview

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(prefix, app) ⇒ MountedPath

Returns a new instance of MountedPath

Since:

  • 0.1.0

def initialize(prefix, app)
  @prefix = prefix
  @app = app
end

Instance Method Details

#endpoint_and_params(env) ⇒ Object

Since:

  • 0.1.0

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