Module: Grape::DSL::Middleware

Included in:
API::Instance
Defined in:
lib/grape/dsl/middleware.rb

Instance Method Summary collapse

Instance Method Details

#middlewareObject

Retrieve an array of the middleware classes and arguments that are currently applied to the application.



31
32
33
# File 'lib/grape/dsl/middleware.rb', line 31

def middleware
  inheritable_setting.namespace_stackable[:middleware] || []
end

#use(middleware_class, *args, &block) ⇒ Object

Apply a custom middleware to the API. Applies to the current namespace and any children, but not parents.

Parameters:

  • middleware_class (Class)

    The class of the middleware you’d like to inject.



12
13
14
15
16
17
# File 'lib/grape/dsl/middleware.rb', line 12

def use(middleware_class, *args, &block)
  arr = [:use, middleware_class, *args]
  arr << block if block

  inheritable_setting.namespace_stackable[:middleware] = arr
end