Module: Grape::DSL::Middleware::ClassMethods

Defined in:
lib/grape/dsl/middleware.rb

Instance Method Summary collapse

Instance Method Details

#insert(*args, &block) ⇒ Object


26
27
28
29
30
31
# File 'lib/grape/dsl/middleware.rb', line 26

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

  namespace_stackable(:middleware, arr)
end

#insert_after(*args, &block) ⇒ Object


40
41
42
43
44
45
# File 'lib/grape/dsl/middleware.rb', line 40

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

  namespace_stackable(:middleware, arr)
end

#insert_before(*args, &block) ⇒ Object


33
34
35
36
37
38
# File 'lib/grape/dsl/middleware.rb', line 33

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

  namespace_stackable(:middleware, arr)
end

#middlewareObject

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


50
51
52
# File 'lib/grape/dsl/middleware.rb', line 50

def middleware
  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.


19
20
21
22
23
24
# File 'lib/grape/dsl/middleware.rb', line 19

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

  namespace_stackable(:middleware, arr)
end