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
-
#matcher ⇒ Object
readonly
Returns the value of attribute matcher.
Attributes inherited from HttpRouter::Node
Instance Method Summary collapse
-
#initialize(router, parent, matcher) ⇒ FreeRegex
constructor
A new instance of FreeRegex.
- #to_code ⇒ Object
- #usable?(other) ⇒ Boolean
Methods inherited from HttpRouter::Node
#add_destination, #add_free_match, #add_glob, #add_glob_regexp, #add_host, #add_lookup, #add_match, #add_request_method, #add_scheme, #add_spanning_match, #add_user_agent, #add_variable, #depth, #inspect, #inspect_label, #inspect_matchers_body
Constructor Details
#initialize(router, parent, matcher) ⇒ FreeRegex
Returns 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
#matcher ⇒ Object (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
#to_code ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/http_router/node/free_regex.rb', line 10 def to_code id = root.next_counter "whole_path#{id} = \"/\#{request.joined_path}\" if match = #{matcher.inspect}.match(whole_path#{id}) and match[0].size == whole_path#{id}.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 |
#usable?(other) ⇒ Boolean
28 29 30 |
# File 'lib/http_router/node/free_regex.rb', line 28 def usable?(other) other.class == self.class && other.matcher == matcher end |