Class: Hanami::API::Middleware::Stack Private
- Inherits:
-
Object
- Object
- Hanami::API::Middleware::Stack
- Defined in:
- lib/hanami/api/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.
Middleware stack
Instance Method Summary collapse
- #finalize(app) ⇒ Object private
-
#initialize(prefix) ⇒ Stack
constructor
private
A new instance of Stack.
- #to_hash ⇒ Object private
- #use(path, middleware, *args, &blk) ⇒ Object private
Constructor Details
#initialize(prefix) ⇒ Stack
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.
Returns a new instance of Stack.
20 21 22 23 |
# File 'lib/hanami/api/middleware.rb', line 20 def initialize(prefix) @prefix = prefix @stack = {} end |
Instance Method Details
#finalize(app) ⇒ Object
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.
43 44 45 46 47 48 |
# File 'lib/hanami/api/middleware.rb', line 43 def finalize(app) mapping = to_hash return app if mapping.empty? App.new(app, mapping) end |
#to_hash ⇒ Object
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.
35 36 37 38 39 |
# File 'lib/hanami/api/middleware.rb', line 35 def to_hash @stack.each_with_object({}) do |(path, _), result| result[path] = stack_for(path) end end |
#use(path, middleware, *args, &blk) ⇒ Object
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.
27 28 29 30 31 |
# File 'lib/hanami/api/middleware.rb', line 27 def use(path, middleware, *args, &blk) # FIXME: test with prefix when Hanami::API.settings and prefix will be supported @stack[path] ||= [] @stack[path].push([middleware, args, blk]) end |