Sha256: a5a2fa13e28f537f70976a96fa92e40351cec8126900a96422b865eec40f5d2c

Contents?: true

Size: 951 Bytes

Versions: 2

Compression:

Stored size: 951 Bytes

Contents

# frozen_string_literal: true

module Dynflow
  class Middleware::Stack
    include Algebrick::TypeCheck

    attr_reader :action, :middleware_class, :middleware

    def self.build(middleware_classes, method, action, &block)
      middleware_classes.reverse_each.reduce(block) do |stack, klass|
        Middleware::Stack.new(stack, klass, method, action)
      end
    end

    def initialize(next_stack, middleware_class, method, action)
      @middleware_class = Child! middleware_class, Middleware
      @middleware       = middleware_class.new self
      @action           = Type! action, Dynflow::Action, NilClass
      @method           = Match! method, :delay, :plan, :run, :finalize, :plan_phase, :finalize_phase, :present, :hook
      @next_stack       = Type! next_stack, Middleware::Stack, Proc
    end

    def call(*args)
      @middleware.send @method, *args
    end

    def pass(*args)
      @next_stack.call(*args)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dynflow-1.9.0 lib/dynflow/middleware/stack.rb
dynflow-1.8.3 lib/dynflow/middleware/stack.rb