Class: Hanami::API::Middleware::Stack Private

Inherits:
Object
  • Object
show all
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

Since:

  • 0.1.0

Instance Method Summary collapse

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.

Since:

  • 0.1.0



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.

Since:

  • 0.1.1



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_hashObject

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.

Since:

  • 0.1.1



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.

Since:

  • 0.1.0



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