Class: HttpRouter::Node::SpanningRegex

Inherits:
Regex show all
Defined in:
lib/http_router/node/spanning_regex.rb

Instance Attribute Summary

Attributes inherited from Regex

#capturing_indicies, #matcher, #ordered_indicies, #splitting_indicies

Attributes inherited from HttpRouter::Node

#router

Instance Method Summary collapse

Methods inherited from Regex

#initialize, #node_to_code, #param_capturing_code, #usable?

Methods inherited from HttpRouter::Node

#add_arbitrary, #add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_lookup, #add_match, #add_request, #add_spanning_match, #add_variable, #depth, #initialize, #inspect, #inspect_label, #inspect_matchers_body, #usable?

Constructor Details

This class inherits a constructor from HttpRouter::Node::Regex

Instance Method Details

#to_codeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/http_router/node/spanning_regex.rb', line 4

def to_code
  params_count = @ordered_indicies.size
  whole_path_var = "whole_path#{root.next_counter}"
  "#{whole_path_var} = request.joined_path
  if match = #{@matcher.inspect}.match(#{whole_path_var}) and match.begin(0).zero?
    _#{whole_path_var} = request.path.dup
    " << param_capturing_code << "
    remaining_path = #{whole_path_var}[match[0].size + (#{whole_path_var}[match[0].size] == ?/ ? 1 : 0), #{whole_path_var}.size]
    request.path = remaining_path.split('/')
    #{node_to_code}
    request.path = _#{whole_path_var}
    request.params.slice!(#{-params_count.size}, #{params_count})
  end
  "
end