Sha256: 701237858802c72856a15e01af5ba86e6d1d19d6f6e235181615d1bbe68d5914

Contents?: true

Size: 1.11 KB

Versions: 13

Compression:

Stored size: 1.11 KB

Contents

# frozen_string_literal: true

require "hanami/router/formatter/human_friendly"

module Hanami
  class Router
    # Builds a representation of an array of routes according to a given formatter.
    #
    # @see Router.new
    #
    # @since 2.0.0
    # @api private
    class Inspector
      # @param routes [Array<Hanami::Route>]
      # @param formatter [#call] routes formatter, taking routes as an argument and returning its
      #   own representation (typically a string). Defaults to {Formatter::HumanFriendly}.
      #
      # @since 2.0.0
      # @api public
      def initialize(routes: [], formatter: Formatter::HumanFriendly.new)
        @routes = routes
        @formatter = formatter
      end

      # Adds a route to be inspected.
      #
      # @param route [Route]
      #
      # @since 2.0.0
      # @api public
      def add_route(route)
        @routes.push(route)
      end

      # Calls the formatter for all added routes.
      #
      # @return [Any] Formatted routes
      #
      # @since 2.0.0
      # @api public
      def call(...)
        @formatter.call(@routes, ...)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hanami-router-2.2.0 lib/hanami/router/inspector.rb
hanami-router-2.2.0.rc1 lib/hanami/router/inspector.rb
hanami-router-2.2.0.beta2 lib/hanami/router/inspector.rb
hanami-router-2.2.0.beta1 lib/hanami/router/inspector.rb
hanami-router-2.1.0 lib/hanami/router/inspector.rb
hanami-router-2.1.0.rc3 lib/hanami/router/inspector.rb
hanami-router-2.1.0.rc2 lib/hanami/router/inspector.rb
hanami-router-2.1.0.rc1 lib/hanami/router/inspector.rb
hanami-router-2.1.0.beta1 lib/hanami/router/inspector.rb
hanami-router-2.0.2 lib/hanami/router/inspector.rb
hanami-router-2.0.1 lib/hanami/router/inspector.rb
hanami-router-2.0.0 lib/hanami/router/inspector.rb
hanami-router-2.0.0.rc1 lib/hanami/router/inspector.rb