Sha256: daa7e1d58bc165b3612f2f773d6329ef9c75b7173fbaf4cbfb1506438acfddac

Contents?: true

Size: 1.57 KB

Versions: 15

Compression:

Stored size: 1.57 KB

Contents

require 'hanami/routing/default'
require_relative './app/routes'

module Hanami
  # @since 0.9.0
  # @api private
  module Components
    # Project's routes inspector
    #
    # @since 0.9.0
    # @api private
    class RoutesInspector
      # @param configuration [Hanami::Configuration]
      #
      # @since 0.9.0
      # @api private
      def initialize(configuration)
        @configuration = configuration
      end

      # Returns a printable version of the project routes
      #
      # @return [String] printable routes
      #
      # @since 0.9.0
      # @api private
      def inspect
        routes.map do |r|
          r.inspector.to_s
        end.join("\n")
      end

      private

      # @since 0.9.0
      # @api private
      attr_reader :configuration

      # @since 0.9.0
      # @api private
      def routes
        configuration.mounted.each_with_object([]) do |(klass, app), result|
          result << if hanami_app?(klass)
                      resolve_hanami_app_router(app)
                    else
                      resolve_rack_app_router(app)
                    end
        end
      end

      # @since 0.9.0
      # @api private
      def hanami_app?(klass)
        klass.ancestors.include?(Hanami::Application)
      end

      # @since 0.9.0
      # @api private
      def resolve_hanami_app_router(app)
        App::Routes.application_routes(app)
      end

      # @since 0.9.0
      # @api private
      def resolve_rack_app_router(app)
        Hanami::Router.new do
          mount app.name, at: app.path_prefix
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
hanami-1.3.0.beta1 lib/hanami/components/routes_inspector.rb
hanami-1.2.0 lib/hanami/components/routes_inspector.rb
hanami-1.2.0.rc2 lib/hanami/components/routes_inspector.rb
hanami-1.2.0.rc1 lib/hanami/components/routes_inspector.rb
hanami-1.2.0.beta2 lib/hanami/components/routes_inspector.rb
hanami-1.2.0.beta1 lib/hanami/components/routes_inspector.rb
hanami-1.1.1 lib/hanami/components/routes_inspector.rb
hanami-1.1.0 lib/hanami/components/routes_inspector.rb
hanami-1.1.0.rc1 lib/hanami/components/routes_inspector.rb
hanami-1.1.0.beta3 lib/hanami/components/routes_inspector.rb
hanami-1.1.0.beta2 lib/hanami/components/routes_inspector.rb
hanami-1.1.0.beta1 lib/hanami/components/routes_inspector.rb
hanami-1.0.0 lib/hanami/components/routes_inspector.rb
hanami-1.0.0.rc1 lib/hanami/components/routes_inspector.rb
hanami-1.0.0.beta3 lib/hanami/components/routes_inspector.rb