Class: HttpRouter::Node::FreeRegex

Inherits:
HttpRouter::Node show all
Defined in:
lib/http_router/node/free_regex.rb

Instance Attribute Summary collapse

Attributes inherited from HttpRouter::Node

#priority, #router

Instance Method Summary collapse

Methods inherited from HttpRouter::Node

#add_arbitrary, #add_destination, #add_free_match, #add_glob, #add_lookup, #add_match, #add_request, #add_spanning_match, #add_variable, #arbitrary, #destination, #glob, #join_whole_path, #linear, #lookup, #request, #unescape, #variable

Constructor Details

#initialize(router, matcher) ⇒ FreeRegex

Returns a new instance of FreeRegex.



5
6
7
# File 'lib/http_router/node/free_regex.rb', line 5

def initialize(router, matcher)
  @router, @matcher = router, matcher
end

Instance Attribute Details

#matcherObject (readonly)

Returns the value of attribute matcher.



4
5
6
# File 'lib/http_router/node/free_regex.rb', line 4

def matcher
  @matcher
end

Instance Method Details

#[](request) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/http_router/node/free_regex.rb', line 9

def [](request)
  whole_path = "/#{join_whole_path(request)}"
  if match = @matcher.match(whole_path) and match[0].size == whole_path.size
    request = request.clone
    request.extra_env['router.regex_match'] = match
    match.names.size.times{|i| request.params << match[i + 1]} if match.respond_to?(:names) && match.names
    super
  end
end