Class: Hanami::Middleware Private
- Inherits:
-
Object
- Object
- Hanami::Middleware
- Defined in:
- lib/hanami/middleware.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Rack middleware stack for an application
Instance Method Summary collapse
-
#call(env) ⇒ Array
private
Process a request.
-
#initialize(configuration) ⇒ Hanami::Middleware
constructor
private
Instantiate a middleware stack.
-
#load! ⇒ Hanami::Middleware
private
Load the middleware stack.
-
#prepend(middleware, *args, &blk) ⇒ Array
private
Prepend a middleware to the stack.
-
#use(middleware, *args, &blk) ⇒ Array
private
Append a middleware to the stack.
Constructor Details
#initialize(configuration) ⇒ Hanami::Middleware
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Instantiate a middleware stack
20 21 22 23 24 |
# File 'lib/hanami/middleware.rb', line 20 def initialize(configuration) @stack = [] @configuration = configuration @builder = Rack::Builder.new end |
Instance Method Details
#call(env) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Process a request. This method makes the middleware stack compatible with the Rack protocol.
51 52 53 |
# File 'lib/hanami/middleware.rb', line 51 def call(env) builder.call(env) end |
#load! ⇒ Hanami::Middleware
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load the middleware stack
34 35 36 37 38 39 40 |
# File 'lib/hanami/middleware.rb', line 34 def load! load_default_stack stack.each { |m, args, block| builder.use(load_middleware(m), *args, &block) } builder.run routes self end |
#prepend(middleware, *args, &blk) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Prepend a middleware to the stack.
82 83 84 85 |
# File 'lib/hanami/middleware.rb', line 82 def prepend(middleware, *args, &blk) stack.unshift [middleware, args, blk] stack.uniq! end |
#use(middleware, *args, &blk) ⇒ Array
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Append a middleware to the stack.
66 67 68 69 |
# File 'lib/hanami/middleware.rb', line 66 def use(middleware, *args, &blk) stack.push [middleware, args, blk] stack.uniq! end |