forked from ruby-grape/grape
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.rb
33 lines (28 loc) · 875 Bytes
/
middleware.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 = [middleware_class, *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