Sha256: f132aa8e190325fe348dc64378fdfe7d58dcc193eb123f860b776d9e0128fbfb

Contents?: true

Size: 1.29 KB

Versions: 5

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true

require "hanami/router"
require "hanami/application/routing/middleware/stack"

module Hanami
  class Application
    # Hanami application router
    # @since 2.0.0
    class Router < ::Hanami::Router
      # @since 2.0.0
      # @api private
      def initialize(routes:, middleware_stack: Routing::Middleware::Stack.new, **kwargs, &blk)
        @middleware_stack = middleware_stack
        instance_eval(&blk)
        super(**kwargs, &routes)
      end

      # @since 2.0.0
      # @api private
      def freeze
        return self if frozen?

        remove_instance_variable(:@middleware_stack)
        super
      end

      # @since 2.0.0
      # @api private
      def use(middleware, *args, &blk)
        @middleware_stack.use(middleware, *args, &blk)
      end

      # @since 2.0.0
      # @api private
      def scope(*args, &blk)
        @middleware_stack.with(args.first) do
          super
        end
      end

      # @since 2.0.0
      def slice(name, at:, &blk)
        path = prefixed_path(at)
        @resolver.register_slice_at_path(name, path)

        scope(path, &blk)
      end

      # @since 2.0.0
      # @api private
      def to_rack_app
        return self if @middleware_stack.empty?

        @middleware_stack.to_rack_app(self)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hanami-2.0.0.alpha8 lib/hanami/application/router.rb
hanami-2.0.0.alpha7.1 lib/hanami/application/router.rb
hanami-2.0.0.alpha7 lib/hanami/application/router.rb
hanami-2.0.0.alpha6 lib/hanami/application/router.rb
hanami-2.0.0.alpha5 lib/hanami/application/router.rb