Class: Kirei::Routing::Router
- Inherits:
-
Object
- Object
- Kirei::Routing::Router
- Extended by:
- T::Sig
- Includes:
- Singleton
- Defined in:
- lib/kirei/routing/router.rb
Overview
Usage:
Router.add_routes([
Route.new(
verb: Verb::GET,
path: "/livez",
controller: Controllers::HealthController,
action: "livez",
),
])
Constant Summary collapse
- RoutesHash =
T.type_alias do T::Hash[String, Route] end
Instance Attribute Summary collapse
-
#routes ⇒ Object
readonly
Returns the value of attribute routes.
Class Method Summary collapse
Instance Method Summary collapse
- #get(verb, path) ⇒ Object
-
#initialize ⇒ Router
constructor
A new instance of Router.
Constructor Details
#initialize ⇒ Router
Returns a new instance of Router.
29 30 31 |
# File 'lib/kirei/routing/router.rb', line 29 def initialize @routes = T.let({}, RoutesHash) end |
Instance Attribute Details
#routes ⇒ Object (readonly)
Returns the value of attribute routes.
34 35 36 |
# File 'lib/kirei/routing/router.rb', line 34 def routes @routes end |
Class Method Details
.add_routes(routes) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/kirei/routing/router.rb', line 48 def self.add_routes(routes) routes.each do |route| key = "#{route.verb.serialize} #{route.path}" instance.routes[key] = route end end |
Instance Method Details
#get(verb, path) ⇒ Object
42 43 44 45 |
# File 'lib/kirei/routing/router.rb', line 42 def get(verb, path) key = "#{verb.serialize} #{path}" routes[key] end |