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.
19 20 21 22 |
# File 'lib/hanami/api/middleware.rb', line 19 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.
42 43 44 45 46 47 |
# File 'lib/hanami/api/middleware.rb', line 42 def finalize(app) mapping = to_hash return app if mapping.empty? Hanami::Middleware::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.
34 35 36 37 38 |
# File 'lib/hanami/api/middleware.rb', line 34 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.
26 27 28 29 30 |
# File 'lib/hanami/api/middleware.rb', line 26 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 |