class Scorched::Request

Public Instance Methods

all_captures() click to toggle source

Returns an array of capture arrays; one for each mapping that’s been hit during the request processing so far.

# File lib/scorched/request.rb, line 17
def all_captures
  breadcrumb.map { |match| match.captures }
end
breadcrumb() click to toggle source

Keeps track of the matched URL portions and what object handled them. Useful for debugging and building breadcrumb navigation.

captures() click to toggle source

Returns a hash of captured strings from the last matched URL in the breadcrumb.

# File lib/scorched/request.rb, line 12
def captures
  breadcrumb.last ? breadcrumb.last.captures : []
end
matched_path() click to toggle source

The portion of the path that’s currently been matched by one or more mappings.

# File lib/scorched/request.rb, line 22
def matched_path
  join_paths(breadcrumb.map{ |match| match.path })
end
unescaped_path() click to toggle source

The unescaped URL, excluding the escaped forward-slash and percent. The resulting string will always be safe to unescape again in situations where the forward-slash or percent are expected and valid characters.

# File lib/scorched/request.rb, line 35
def unescaped_path
  path_info.split(/(%25|%2F)/i).each_slice(2).map { |v, m| CGI.unescape(v) << (m || '') }.join('')
end
unmatched_path() click to toggle source

The remaining portion of the path that has yet to be matched by any mappings.

# File lib/scorched/request.rb, line 27
def unmatched_path
  path = unescaped_path
  path[0,0] = '/' if (path[0] != '/' && matched_path[-1] == '/') || path.empty?
  path
end

Private Instance Methods

join_paths(paths) click to toggle source

Joins an array of path segments ensuring a single forward slash seperates them.

# File lib/scorched/request.rb, line 42
def join_paths(paths)
  paths.join('/').gsub(%r{/+}, '/')
end