Class: Hanami::Routes

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/routes.rb

Overview

App routes

Users are expected to inherit from this class to define their app routes.

Examples:

# config/routes.rb
# frozen_string_literal: true

require "hanami/routes"

module MyApp
  class Routes < Hanami::Routes
    root to: "home.show"
  end
end

See {Hanami::Slice::Router} for the syntax allowed within the `define` block.

See Also:

Since:

  • 2.0.0

Defined Under Namespace

Classes: MissingActionError, NotCallableEndpointError, RoutesProc

Class Method Summary collapse

Class Method Details

.build_routes(definitions = self.definitions) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/hanami/routes.rb', line 99

def build_routes(definitions = self.definitions)
  return RoutesProc.empty if definitions.empty?

  routes_proc = proc do
    definitions.each do |(name, args, kwargs, block)|
      if block
        public_send(name, *args, **kwargs, &block)
      else
        public_send(name, *args, **kwargs)
      end
    end
  end

  RoutesProc.new(routes_proc)
end

.definitionsObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



116
117
118
# File 'lib/hanami/routes.rb', line 116

def definitions
  @definitions ||= []
end

.routesObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.0



93
94
95
# File 'lib/hanami/routes.rb', line 93

def self.routes
  @routes ||= build_routes
end