Module: Roda::RodaPlugins::StaticPathInfo::RequestMethods

Defined in:
lib/roda/plugins/static_path_info.rb

Constant Summary collapse

PATH_INFO =
"PATH_INFO".freeze
SCRIPT_NAME =
"SCRIPT_NAME".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#remaining_pathObject (readonly)

The current path to match requests against. This is initialized to PATH_INFO when the request is created.



19
20
21
# File 'lib/roda/plugins/static_path_info.rb', line 19

def remaining_path
  @remaining_path
end

Instance Method Details

#initializeObject

Set remaining_path when initializing.



22
23
24
25
# File 'lib/roda/plugins/static_path_info.rb', line 22

def initialize(*)
  super
  @remaining_path = @env[PATH_INFO]
end

#matched_pathObject

The already matched part of the path, including the original SCRIPT_NAME.



28
29
30
31
# File 'lib/roda/plugins/static_path_info.rb', line 28

def matched_path
  e = @env
  e[SCRIPT_NAME] + e[PATH_INFO].chomp(@remaining_path)
end

#run(_) ⇒ Object

Update SCRIPT_NAME/PATH_INFO based on the current remaining_path before dispatching to another rack app, so the app still works as a URL mapper.



36
37
38
39
40
41
42
# File 'lib/roda/plugins/static_path_info.rb', line 36

def run(_)
  e = @env
  path = @remaining_path
  e[SCRIPT_NAME] += e[PATH_INFO].chomp(path)
  e[PATH_INFO] = path
  super
end