class Hanami::Routes

App routes

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

@example

# 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 Hanami::Slice::Router @since 2.0.0

Public Class Methods

build_routes(definitions = self.definitions) click to toggle source

@api private

# 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
definitions() click to toggle source

@api private

# File lib/hanami/routes.rb, line 116
def definitions
  @definitions ||= []
end
routes() click to toggle source

@api private

# File lib/hanami/routes.rb, line 93
def self.routes
  @routes ||= build_routes
end

Private Class Methods

method_missing(name, *args, **kwargs, &block) click to toggle source

Capture all method calls that are supported by the router DSL so that it can be evaluated lazily during configuration/boot process

@api private

Calls superclass method
# File lib/hanami/routes.rb, line 137
def method_missing(name, *args, **kwargs, &block)
  return super unless respond_to?(name)
  definitions << [name, args, kwargs, block]
  self
end
respond_to_missing?(name, include_private = false) click to toggle source

@api private

Calls superclass method
# File lib/hanami/routes.rb, line 128
def respond_to_missing?(name, include_private = false)
  supported_methods.include?(name) || super
end
supported_methods() click to toggle source

@api private

# File lib/hanami/routes.rb, line 123
def supported_methods
  @supported_methods ||= Slice::Router.public_instance_methods
end