Class: HttpRouter::Node::FreeRegex
- Inherits:
-
HttpRouter::Node
- Object
- HttpRouter::Node
- HttpRouter::Node::FreeRegex
- Defined in:
- lib/http_router/node/free_regex.rb
Instance Attribute Summary (collapse)
-
- (Object) matcher
readonly
Returns the value of attribute matcher.
Attributes inherited from HttpRouter::Node
#node_position, #parent, #priority, #router
Instance Method Summary (collapse)
-
- (FreeRegex) initialize(router, parent, matcher)
constructor
A new instance of FreeRegex.
- - (Object) to_code
- - (Boolean) usable?(other)
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
Constructor Details
- (FreeRegex) initialize(router, parent, matcher)
A new instance of FreeRegex
5 6 7 8 |
# File 'lib/http_router/node/free_regex.rb', line 5 def initialize(router, parent, matcher) @matcher = matcher super(router, parent) end |
Instance Attribute Details
- (Object) matcher (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
- (Object) to_code
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/http_router/node/free_regex.rb', line 10 def to_code "whole_path#{depth} = \"/\#{request.joined_path}\" if match = #{matcher.inspect}.match(whole_path#{depth}) and match[0].size == whole_path#{depth}.size request.extra_env['router.regex_match'] = match old_path = request.path request.path = [''] " << (use_named_captures? ? "match.names.size.times{|i| request.params << match[i + 1]} if match.respond_to?(:names) && match.names" : "") << " #{super} request.path = old_path request.extra_env.delete('router.regex_match') " << (use_named_captures? ? "params.slice!(-match.names.size, match.names.size)" : "" ) << " end" end |
- (Boolean) usable?(other)
27 28 29 |
# File 'lib/http_router/node/free_regex.rb', line 27 def usable?(other) other.class == self.class && other.matcher == matcher end |