Class: Hanami::Router::Inspector Private

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

Overview

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

Builds a representation of an array of routes according to a given formatter.

See Also:

  • Router.new

Since:

  • 2.0.0

Instance Method Summary collapse

Constructor Details

#initialize(routes: [], formatter: Formatter::HumanFriendly.new) ⇒ Inspector

Returns a new instance of Inspector.

Parameters:

  • routes (Array<Hanami::Route>) (defaults to: [])
  • formatter (#call) (defaults to: Formatter::HumanFriendly.new)

    routes formatter, taking routes as an argument and returning its own representation (typically a string). Defaults to Formatter::HumanFriendly.

Since:

  • 2.0.0



20
21
22
23
# File 'lib/hanami/router/inspector.rb', line 20

def initialize(routes: [], formatter: Formatter::HumanFriendly.new)
  @routes = routes
  @formatter = formatter
end

Instance Method Details

#add_route(route) ⇒ Object

Adds a route to be inspected.

Parameters:

Since:

  • 2.0.0



31
32
33
# File 'lib/hanami/router/inspector.rb', line 31

def add_route(route)
  @routes.push(route)
end

#callAny

Calls the formatter for all added routes.

Returns:

  • (Any)

    Formatted routes

Since:

  • 2.0.0



41
42
43
# File 'lib/hanami/router/inspector.rb', line 41

def call(...)
  @formatter.call(@routes, ...)
end