Sha256: 10231d26d8ca0190d54c06d97d534c7ae57b0765ed22e88b2ae6ef402cb3679d

Contents?: true

Size: 1.21 KB

Versions: 10

Compression:

Stored size: 1.21 KB

Contents

require 'active_support/concern'

module Grape
  module DSL
    module Middleware
      extend ActiveSupport::Concern

      include Grape::DSL::Configuration

      module ClassMethods
        # Apply a custom middleware to the API. Applies
        # to the current namespace and any children, but
        # not parents.
        #
        # @param middleware_class [Class] The class of the middleware you'd like
        #   to inject.
        def use(middleware_class, *args, &block)
          arr = [:use, middleware_class, *args]
          arr << block if block_given?

          namespace_stackable(:middleware, arr)
        end

        def insert_before(*args, &block)
          arr = [:insert_before, *args]
          arr << block if block_given?

          namespace_stackable(:middleware, arr)
        end

        def insert_after(*args, &block)
          arr = [:insert_after, *args]
          arr << block if block_given?

          namespace_stackable(:middleware, arr)
        end

        # Retrieve an array of the middleware classes
        # and arguments that are currently applied to the
        # application.
        def middleware
          namespace_stackable(:middleware) || []
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
grape-1.1.0 lib/grape/dsl/middleware.rb
grape-1.0.3 lib/grape/dsl/middleware.rb
grape-1.0.2 lib/grape/dsl/middleware.rb
grape-1.0.1 lib/grape/dsl/middleware.rb
grape-1.0.0 lib/grape/dsl/middleware.rb
grape-0.19.2 lib/grape/dsl/middleware.rb
grape-0.19.1 lib/grape/dsl/middleware.rb
grape-0.19.0 lib/grape/dsl/middleware.rb
grape-0.18.0 lib/grape/dsl/middleware.rb
grape-0.17.0 lib/grape/dsl/middleware.rb