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

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



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/hanami/routes.rb', line 70

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

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



85
86
87
# File 'lib/hanami/routes.rb', line 85

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



64
65
66
# File 'lib/hanami/routes.rb', line 64

def self.routes
  @routes ||= build_routes
end