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

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

Instance Method Summary collapse

Instance Method Details

#insert(*args, &block) ⇒ Object



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

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

  namespace_stackable(:middleware, arr)
end

#insert_after(*args, &block) ⇒ Object



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

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

  namespace_stackable(:middleware, arr)
end

#insert_before(*args, &block) ⇒ Object



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

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

  namespace_stackable(:middleware, arr)
end

#middlewareObject

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



48
49
50
# File 'lib/grape/dsl/middleware.rb', line 48

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.



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

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

  namespace_stackable(:middleware, arr)
end