Class: Scorched::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/scorched/request.rb

Instance Method Summary collapse

Instance Method Details

#all_capturesObject

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


17
18
19
# File 'lib/scorched/request.rb', line 17

def all_captures
  breadcrumb.map { |match| match.captures }
end

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


7
8
9
# File 'lib/scorched/request.rb', line 7

def breadcrumb
  env['scorched.breadcrumb'] ||= []
end

#capturesObject

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


12
13
14
# File 'lib/scorched/request.rb', line 12

def captures
  breadcrumb.last ? breadcrumb.last.captures : []
end

#matched_pathObject

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


22
23
24
# File 'lib/scorched/request.rb', line 22

def matched_path
  join_paths(breadcrumb.map{ |match| match.path })
end

#unescaped_pathObject

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.


35
36
37
# File 'lib/scorched/request.rb', line 35

def unescaped_path
  path_info.split(/(%25|%2F)/i).each_slice(2).map { |v, m| URI.unescape(v) << (m || '') }.join('')
end

#unmatched_pathObject

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


27
28
29
30
31
# 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