Class: Hanami::Middleware Private

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

Rack middleware stack for an application

Since:

  • 0.1.0

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Hanami::Middleware

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

Parameters:

See Also:

Since:

  • 0.1.0


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

Parameters:

  • env (Hash)

    a Rack env

Returns:

  • (Array)

    a serialized Rack response

Since:

  • 0.1.0


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

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

#load!Hanami::Middleware

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

Returns:

See Also:

Since:

  • 0.2.0


34
35
36
37
38
39
40
# File 'lib/hanami/middleware.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.

Parameters:

  • middleware (Object)

    a Rack middleware

  • args (Array)

    optional arguments to pass to the Rack middleware

  • blk (Proc)

    an optional block to pass to the Rack middleware

Returns:

  • (Array)

    the middleware that was added

See Also:

Since:

  • 0.6.0


82
83
84
85
# File 'lib/hanami/middleware.rb', line 82

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.

Parameters:

  • middleware (Object)

    a Rack middleware

  • args (Array)

    optional arguments to pass to the Rack middleware

  • blk (Proc)

    an optional block to pass to the Rack middleware

Returns:

  • (Array)

    the middleware that was added

See Also:

Since:

  • 0.2.0


66
67
68
69
# File 'lib/hanami/middleware.rb', line 66

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