Class: Hanami::MiddlewareStack Private

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/middleware_stack.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

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Hanami::MiddlewareStack

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

See Also:

Since:

  • 0.1.0


20
21
22
23
24
# File 'lib/hanami/middleware_stack.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.

Since:

  • 0.1.0


51
52
53
# File 'lib/hanami/middleware_stack.rb', line 51

def call(env)
  builder.call(env)
end

#load!Hanami::MiddlewareStack

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_stack.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.

Examples:

# apps/web/application.rb
module Web
  class Application < Hanami::Application
    configure do
      # ...
      prepend MyRackMiddleware, foo: 'bar'
    end
  end
end

See Also:

Since:

  • 0.6.0


104
105
106
107
# File 'lib/hanami/middleware_stack.rb', line 104

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.

Examples:

# apps/web/application.rb
module Web
  class Application < Hanami::Application
    configure do
      # ...
      use MyRackMiddleware, foo: 'bar'
    end
  end
end

See Also:

Since:

  • 0.2.0


77
78
79
80
# File 'lib/hanami/middleware_stack.rb', line 77

def use(middleware, *args, &blk)
  stack.push [middleware, args, blk]
  stack.uniq!
end