Class: Jets::Router::Matcher

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/router/matcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, method) ⇒ Matcher

Returns a new instance of Matcher.



3
4
5
6
# File 'lib/jets/router/matcher.rb', line 3

def initialize(path, method)
  @path = path.sub(/^\//,'')
  @method = method.to_s.upcase
end

Instance Method Details

#match?(route) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/jets/router/matcher.rb', line 8

def match?(route)
  # Immediately stop checking when the request method: GET, POST, ANY, etc
  # doesnt match.

  return false if method != route.method && route.method != "ANY"

  route_path = route.path

  if path == route_path
    # regular string match detection
    return true # exact route matches are highest precedence
  end

  # Check path for route capture and wildcard matches:
  # A colon (:) means the variable has a variable
  if route_path.include?(':') # 2nd highest precedence
    capture_detection(route_path, path) # early return true or false
  # A star (*) means the variable has a glob
  elsif route_path.include?('*') # lowest precedence
    proxy_detection(route_path, path) # early return true or false
  else
    false # reach here, means no route matched
  end
end