Class: Catalyst::RunStack

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

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ RunStack

Start a RunStack with a block



14
15
16
# File 'lib/catalyst.rb', line 14

def initialize(&block)
  instance_eval(&block) if block_given?
end

Instance Method Details

#call(env = {}) ⇒ Object

Start off the middleware



41
42
43
# File 'lib/catalyst.rb', line 41

def call(env={})
  to_app.call(env)
end

#stackObject

middleware stack



19
20
21
# File 'lib/catalyst.rb', line 19

def stack
  @stack ||= []
end

#to_appObject

Turn this RunStack to a Runner



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

def to_app
  Runner.new(stack)
end

#use(k, *args, &block) ⇒ Object Also known as: run

Use ‘middleware’



24
25
26
27
28
29
30
31
# File 'lib/catalyst.rb', line 24

def use(k, *args, &block)
  if k.is_a?(RunStack)
    stack.concat(k.stack)
  else
    stack << [k, args, block]
  end
  self
end