Class: Aikido::Zen::Request::HeuristicRouter

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/request/heuristic_router.rb

Overview

Simple router implementation that just identifies the currently requested URL as a route, attempting to heuristically substitute any path segments that may look like a parameterized value by something descriptive.

For example, “/categories/123/events/2024-10-01” would be matched as “/categories/:number/events/:date”

Defined Under Namespace

Classes: SecretMatcher

Constant Summary collapse

NUMBER =
/\A\d+\z/
HEX =
/\A[a-f0-9]+\z/i
DATE =
/\A\d{4}-\d{2}-\d{2}|\d{2}-\d{2}-\d{4}\z/
UUID =
/\A
(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}
| 00000000-0000-0000-0000-000000000000
| ffffffff-ffff-ffff-ffff-ffffffffffff
)\z/ix
EMAIL =
/\A
  [a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+
  @
  [a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?
  (?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*
\z/x
IP =
->(segment) {
  IPAddr::RE_IPV4ADDRLIKE.match?(segment) ||
    IPAddr::RE_IPV6ADDRLIKE_COMPRESSED.match?(segment) ||
    IPAddr::RE_IPV6ADDRLIKE_FULL.match?(segment)
}
HASH =
->(segment) { [32, 40, 64, 128].include?(segment.size) && HEX === segment }

Instance Method Summary collapse

Instance Method Details

#recognize(request) ⇒ Aikido::Zen::Route?

Parameters:

Returns:



17
18
19
20
# File 'lib/aikido/zen/request/heuristic_router.rb', line 17

def recognize(request)
  path = parameterize(request.path)
  Route.new(verb: request.request_method, path: path)
end