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

Instance Method Details

#get(path, policy: nil) { ... } ⇒ void

This method returns an undefined value.

RBS:

  • (String, policy: Hash[Symbol, String]?) { () -> untyped } -> void

Parameters:

  • (String)
  • policy: (Hash[Symbol, String], nil) (defaults to: nil)

Yields:

Yield Returns:

  • (Object)


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.

RBS:

  • (String, policy: Hash[Symbol, String]?) { () -> untyped } -> void

Parameters:

  • (String)
  • policy: (Hash[Symbol, String], nil) (defaults to: nil)

Yields:

Yield Returns:

  • (Object)


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?

RBS:

  • (String, String) -> Route?

Parameters:

  • (String)
  • (String)

Returns:



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.

RBS:

  • (String, policy: Hash[Symbol, String]?) { () -> untyped } -> void

Parameters:

  • (String)
  • policy: (Hash[Symbol, String], nil) (defaults to: nil)

Yields:

Yield Returns:

  • (Object)


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.

RBS:

  • (String, String, policy: Hash[Symbol, String]?) { () -> untyped } -> void

Parameters:

  • (String)
  • (String)
  • policy: (Hash[Symbol, String], nil) (defaults to: nil)

Yields:

Yield Returns:

  • (Object)


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

#routesHash[String, Array[Route]]

RBS:

  • () -> Hash[String, Array[Route]]

Returns:

  • (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