Class: Lennarb::MiddlewareStack

Inherits:
Object
  • Object
show all
Defined in:
lib/lennarb/middleware_stack.rb

Overview

Basic middleware stack implementation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app = nil) ⇒ MiddlewareStack

The app’s middleware stack.

Parameters:

  • app (Rack::Builder) (defaults to: nil)


11
12
13
14
# File 'lib/lennarb/middleware_stack.rb', line 11

def initialize(app = nil)
  @app = app
  @store = []
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



5
6
7
# File 'lib/lennarb/middleware_stack.rb', line 5

def app
  @app
end

Instance Method Details

#clearObject

Clear the middleware stack.



44
45
46
# File 'lib/lennarb/middleware_stack.rb', line 44

def clear
  @store.clear
end

#to_aObject

Convert the middleware stack to an array.



52
53
54
# File 'lib/lennarb/middleware_stack.rb', line 52

def to_a
  @store
end

#unshift(middleware, *args, &block) ⇒ Object

Add a middleware to the beginning of the stack.

Parameters:

  • middleware (Class)
  • args (Array)
  • block (Proc)


36
37
38
# File 'lib/lennarb/middleware_stack.rb', line 36

def unshift(middleware, *args, &block)
  @store.unshift([middleware, args, block])
end

#use(middleware, *args, &block) ⇒ Object

Insert a middleware in the stack.

Parameters:

  • middleware (Class)
  • args (Array)
  • block (Proc)


24
25
26
# File 'lib/lennarb/middleware_stack.rb', line 24

def use(middleware, *args, &block)
  @store << [middleware, args, block]
end