Sha256: 19db0d716728eec6e127eaa7da8cc161fa4c33f1968f5ab3f0cf7f4d39d59c31

Contents?: true

Size: 666 Bytes

Versions: 4

Compression:

Stored size: 666 Bytes

Contents

class Woodhouse::MiddlewareStack < Array

  def initialize(config)
    @config = config
  end

  def call(*args, &final)
    stack = make_stack.dup
    next_step = lambda {|*args|
      next_item = stack.shift
      if next_item.nil?
        final.call(*args)
      else
        next_item.call(*args, &next_step)
      end
    }
    next_step.call(*args)
  end

  private

  def make_stack
    @stack ||= 
      map do |item|
        if item.respond_to?(:call)
          item
        elsif item.respond_to?(:new)
          item.new(@config)
        else
          raise ArgumentError, "bad entry #{item.inspect} in middleware stack"
        end
      end
  end

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
woodhouse-1.0.0 lib/woodhouse/middleware_stack.rb
woodhouse-0.1.5 lib/woodhouse/middleware_stack.rb
woodhouse-0.1.2 lib/woodhouse/middleware_stack.rb
woodhouse-0.1.1 lib/woodhouse/middleware_stack.rb