Class: HttpRouter::Node::GlobRegex
- Inherits:
-
Glob
- Object
- HttpRouter::Node
- Glob
- HttpRouter::Node::GlobRegex
- Defined in:
- lib/http_router/node/glob_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) ⇒ GlobRegex
constructor
A new instance of GlobRegex.
- #to_code ⇒ Object
- #usable?(other) ⇒ Boolean
Methods inherited from Glob
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) ⇒ GlobRegex
Returns a new instance of GlobRegex.
5 6 7 8 |
# File 'lib/http_router/node/glob_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/glob_regex.rb', line 4 def matcher @matcher end |
Instance Method Details
#to_code ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/http_router/node/glob_regex.rb', line 14 def to_code id = root.next_counter "request.params << (globbed_params#{id} = []) remaining_parts = request.path.dup while !remaining_parts.empty? and match = remaining_parts.first.match(#{@matcher.inspect}) and match[0] == remaining_parts.first globbed_params#{id} << remaining_parts.shift request.path = remaining_parts #{node_to_code} end request.path[0,0] = request.params.pop" end |
#usable?(other) ⇒ Boolean
10 11 12 |
# File 'lib/http_router/node/glob_regex.rb', line 10 def usable?(other) other.class == self.class && other.matcher == matcher end |