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:

  • (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

#clearvoid

This method returns an undefined value.

Clear the middleware stack.



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

def clear
  @store.clear
end

#to_aArray

Convert the middleware stack to an array.

Returns:



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

def to_a
  @store
end

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

This method returns an undefined value.

Add a middleware to the beginning of the stack.

Parameters:



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) ⇒ void

This method returns an undefined value.

Insert a middleware in the stack.

Parameters:



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

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