lib/wayfarer/middleware/chain.rb in wayfarer-0.4.3 vs lib/wayfarer/middleware/chain.rb in wayfarer-0.4.4
- old
+ new
@@ -1,9 +1,17 @@
# frozen_string_literal: true
module Wayfarer
module Middleware
Chain = Struct.new(:middlewares) do
+ extend Forwardable
+
+ def self.empty
+ new([])
+ end
+
+ delegate push: :middlewares
+
def call(task)
traverse = lambda do |i|
if middlewares[i]
middlewares[i].call(task) { traverse.call(i + 1) }
elsif block_given?