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
43
44
45
46
47
48
49
# File 'lib/roda/plugins/static_path_info.rb', line 36

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