kirei 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/kirei/router.rb DELETED
@@ -1,61 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require("singleton")
5
-
6
- module Kirei
7
- #
8
- # Usage:
9
- #
10
- # Router.add_routes([
11
- # Route.new(
12
- # verb: "GET",
13
- # path: "/livez",
14
- # controller: Controllers::HealthController,
15
- # action: "livez",
16
- # ),
17
- # ])
18
- #
19
- class Router
20
- extend T::Sig
21
- include ::Singleton
22
-
23
- class Route < T::Struct
24
- const :verb, String
25
- const :path, String
26
- const :controller, T.class_of(BaseController)
27
- const :action, String
28
- end
29
-
30
- RoutesHash = T.type_alias do
31
- T::Hash[String, Route]
32
- end
33
-
34
- sig { void }
35
- def initialize
36
- @routes = T.let({}, RoutesHash)
37
- end
38
-
39
- sig { returns(RoutesHash) }
40
- attr_reader :routes
41
-
42
- sig do
43
- params(
44
- verb: String,
45
- path: String,
46
- ).returns(T.nilable(Route))
47
- end
48
- def get(verb, path)
49
- key = "#{verb} #{path}"
50
- routes[key]
51
- end
52
-
53
- sig { params(routes: T::Array[Route]).void }
54
- def self.add_routes(routes)
55
- routes.each do |route|
56
- key = "#{route.verb} #{route.path}"
57
- instance.routes[key] = route
58
- end
59
- end
60
- end
61
- end