Sha256: 89087bb5a083f68fed9b963831156157a666ebc1a1136eee2fe71395750ddbab

Contents?: true

Size: 985 Bytes

Versions: 3

Compression:

Stored size: 985 Bytes

Contents

# frozen_string_literal: true

require "hanami/router/formatter/human_friendly"

module Hanami
  class Router
    # Routes inspector
    #
    # Builds a representation of an array of routes according to a given
    # formatter.
    #
    # @since 2.0.0
    class Inspector
      # @param routes [Array<Hanami::Route>]
      # @param formatter [#call] Takes the routes as an argument and returns
      #   whatever representation it creates. Defaults to
      #   {Hanami::Router::Formatter::HumanFriendly}.
      # @since 2.0.0
      def initialize(routes: [], formatter: Formatter::HumanFriendly.new)
        @routes = routes
        @formatter = formatter
      end

      # @param route [Hash] serialized route
      #
      # @api private
      # @since 2.0.0
      def add_route(route)
        @routes.push(route)
      end

      # @return [Any] Formatted routes
      #
      # @since 2.0.0
      def call(...)
        @formatter.call(@routes, ...)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hanami-router-2.0.0.beta4 lib/hanami/router/inspector.rb
hanami-router-2.0.0.beta2 lib/hanami/router/inspector.rb
hanami-router-2.0.0.beta1 lib/hanami/router/inspector.rb