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
- #each(&blk) ⇒ Object private
- #finalize(app) ⇒ Object private
-
#initialize ⇒ Stack
constructor
private
A new instance of Stack.
- #mapped(builder, prefix, &blk) ⇒ Object private
- #use(middleware, args, &blk) ⇒ Object private
- #with(path) ⇒ Object private
Constructor Details
#initialize ⇒ 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.
24 25 26 27 |
# File 'lib/hanami/api/middleware.rb', line 24 def initialize @prefix = ROOT_PREFIX @stack = Hash.new { |hash, key| hash[key] = [] } end |
Instance Method Details
#each(&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.
68 69 70 71 |
# File 'lib/hanami/api/middleware.rb', line 68 def each(&blk) uniq! @stack.each(&blk) end |
#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.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/hanami/api/middleware.rb', line 47 def finalize(app) # rubocop:disable Metrics/MethodLength uniq! return app if @stack.empty? s = self Rack::Builder.new do s.each do |prefix, stack| s.mapped(self, prefix) do stack.each do |middleware, args, blk| use(middleware, *args, &blk) end end run app end end end |
#mapped(builder, prefix, &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.
75 76 77 78 79 80 81 |
# File 'lib/hanami/api/middleware.rb', line 75 def mapped(builder, prefix, &blk) if prefix == ROOT_PREFIX builder.instance_eval(&blk) else builder.map(prefix, &blk) end end |
#use(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.
31 32 33 |
# File 'lib/hanami/api/middleware.rb', line 31 def use(middleware, args, &blk) @stack[@prefix].push([middleware, args, blk]) end |
#with(path) ⇒ 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.
37 38 39 40 41 42 43 |
# File 'lib/hanami/api/middleware.rb', line 37 def with(path) prefix = @prefix @prefix = path yield ensure @prefix = prefix end |