Module: Grape::DSL::Middleware::ClassMethods
- Defined in:
- lib/grape/dsl/middleware.rb
Instance Method Summary collapse
-
#middleware ⇒ Object
Retrieve an array of the middleware classes and arguments that are currently applied to the application.
-
#use(middleware_class, *args, &block) ⇒ Object
Apply a custom middleware to the API.
Instance Method Details
#middleware ⇒ Object
Retrieve an array of the middleware classes and arguments that are currently applied to the application.
24 25 26 27 28 29 |
# File 'lib/grape/dsl/middleware.rb', line 24 def middleware settings.stack.inject([]) do |a, s| a += s[:middleware] if s[:middleware] a end 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.
15 16 17 18 19 |
# File 'lib/grape/dsl/middleware.rb', line 15 def use(middleware_class, *args, &block) arr = [middleware_class, *args] arr << block if block_given? imbue(:middleware, [arr]) end |