Class: Raki::Builder

Inherits:
Base
  • Object
show all
Defined in:
lib/raki/builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Builder

attr_accessor :stack



7
8
9
10
11
# File 'lib/raki/builder.rb', line 7

def initialize(&block)
  @stack = []
  instance_eval(&block) if block
  chain
end

Instance Method Details

#add(middleware) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/raki/builder.rb', line 13

def add(middleware, ...)
  @stack <<
    if middleware.instance_of?(Class)
      middleware.new(...)
    else
      middleware
    end
end

#call(hsh = {}) ⇒ Object



30
31
32
# File 'lib/raki/builder.rb', line 30

def call(hsh = {})
  @stack.first&.call(hsh)
end

#chainObject



22
23
24
25
26
27
28
# File 'lib/raki/builder.rb', line 22

def chain
  previous = nil
  @stack.each do |app|
    previous.app = app if previous
    previous = app
  end
end