Sha256: 784a5748ea76f611ca0043afc6ab52cde2806ffec784e4fb9fcea79b4d1a29ce

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

require "forwardable"

module Lita
  # Stores Rack middleware for later use in a +Rack::Builder+.
  # @since 4.0.2
  # @api private
  class MiddlewareRegistry
    # A Rack middleware and its initialization arguments.
    MiddlewareWrapper = Struct.new(:middleware, :args, :block)

    extend Forwardable

    def_delegators :@registry, :each, :empty?

    def initialize
      @registry = []
    end

    # Adds a Rack middleware with no initialization arguments.
    # @param middleware [#call] A Rack middleware.
    # @return [void]
    def push(middleware)
      @registry << MiddlewareWrapper.new(middleware, [], nil)
    end
    alias << push

    # Adds a Rack middleware with initialization argumens. Uses the same interface as
    # +Rack::Builder#use+.
    # @param middleware [#call] A Rack middleware.
    # @param args [Array] Arbitrary initialization arguments for the middleware.
    # @yield An optional block to be passed to the constructor of the middleware.
    # @return [void]
    def use(middleware, *args, &block)
      @registry << MiddlewareWrapper.new(middleware, args, block)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rita-5.0.0.alpha.4 lib/lita/middleware_registry.rb
rita-5.0.0.alpha.3 lib/lita/middleware_registry.rb
rita-5.0.0.alpha.2 lib/lita/middleware_registry.rb
rita-5.0.0.alpha.1 lib/lita/middleware_registry.rb