Class: HttpRouter::Node::GlobRegex

Inherits:
Glob show all
Defined in:
lib/http_router/node/glob_regex.rb

Instance Attribute Summary collapse

Attributes inherited from HttpRouter::Node

#router

Instance Method Summary collapse

Methods inherited from Glob

#node_to_code

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

#matcherObject (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_codeObject



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

Returns:

  • (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