Module: SolidObjects::Web::Router
- Included in:
- Application
- Defined in:
- lib/solid_objects/web/router.rb,
sig/generated/lib/solid_objects/web/router.rbs
Overview
Declares the pages of the dashboard. Every route carries the administration policy it needs, and a route declared without one raises at load time. A new page therefore cannot reach the database before an application has said who may read it.
Instance Method Summary collapse
- #get(path, policy: nil) { ... } ⇒ void
- #head(path, policy: nil) { ... } ⇒ void
- #match(request_method, path) ⇒ Route?
- #post(path, policy: nil) { ... } ⇒ void
- #route(request_method, path, policy: nil) { ... } ⇒ void
- #routes ⇒ Hash[String, Array[Route]]
Instance Method Details
#get(path, policy: nil) { ... } ⇒ void
This method returns an undefined value.
16 17 18 |
# File 'lib/solid_objects/web/router.rb', line 16 def get(path, policy: nil, &handler) route("GET", path, policy:, &handler) end |
#head(path, policy: nil) { ... } ⇒ void
This method returns an undefined value.
11 12 13 |
# File 'lib/solid_objects/web/router.rb', line 11 def head(path, policy: nil, &handler) route("HEAD", path, policy:, &handler) end |
#match(request_method, path) ⇒ Route?
41 42 43 |
# File 'lib/solid_objects/web/router.rb', line 41 def match(request_method, path) routes[request_method].find { |route| route.match?(path) } end |
#post(path, policy: nil) { ... } ⇒ void
This method returns an undefined value.
21 22 23 |
# File 'lib/solid_objects/web/router.rb', line 21 def post(path, policy: nil, &handler) route("POST", path, policy:, &handler) end |
#route(request_method, path, policy: nil) { ... } ⇒ void
This method returns an undefined value.
26 27 28 29 30 31 32 33 |
# File 'lib/solid_objects/web/router.rb', line 26 def route(request_method, path, policy: nil, &handler) raise ArgumentError, "route #{path} requires an authorization policy" unless policy raise ArgumentError, "route #{path} requires a handler" unless handler raise ArgumentError, "route #{path} requires a policy action" unless policy[:action] raise ArgumentError, "route #{path} requires a policy resource" unless policy[:resource] routes[request_method] << Route.new(request_method:, pattern: path, policy:, handler:) end |
#routes ⇒ Hash[String, Array[Route]]
36 37 38 |
# File 'lib/solid_objects/web/router.rb', line 36 def routes @routes ||= Hash.new { |store, request_method| store[request_method] = [] } end |