Class: Peictt::Http::Checker

Inherits:
Object
  • Object
show all
Defined in:
lib/peictt/http/checker.rb

Class Method Summary collapse

Class Method Details

.check_url(env, routes) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/peictt/http/checker.rb', line 4

def self.check_url(env, routes)
  routes.each do |route|
    params = {}
    match = route.regexp.match(env["PATH_INFO"])
    if match && ((env["REQUEST_METHOD"] == route.verb) ||
      (route.verb.include? env["REQUEST_METHOD"]))
      unless route.placeholders.empty?
        params = route.placeholders.zip(match.captures).to_h
      end
      return [route, params]
    end
  end

  -> (_env) { [404, {}, ["Route not found"]] }
end