Class: Kirei::Routing::Router

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRouter

Returns a new instance of Router.



32
33
34
# File 'lib/kirei/routing/router.rb', line 32

def initialize
  @routes = T.let({}, RoutesHash)
end

Instance Attribute Details

#current_envObject

Returns the value of attribute current_env.



29
30
31
# File 'lib/kirei/routing/router.rb', line 29

def current_env
  @current_env
end

#routesObject (readonly)

Returns the value of attribute routes.



37
38
39
# File 'lib/kirei/routing/router.rb', line 37

def routes
  @routes
end

Class Method Details

.add_routes(routes) ⇒ Object



51
52
53
54
55
56
# File 'lib/kirei/routing/router.rb', line 51

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



45
46
47
48
# File 'lib/kirei/routing/router.rb', line 45

def get(verb, path)
  key = "#{verb.serialize} #{path}"
  routes[key]
end