Sha256: 8f156279d6471b963570dd91aab43409adfbffdbff679b2112273f683ac5c21b

Contents?: true

Size: 712 Bytes

Versions: 1

Compression:

Stored size: 712 Bytes

Contents

module Rodimus

  class Transformation
    attr_reader :steps

    def initialize
      @steps = []
    end

    def run
      prepare

      steps.each do |step|
        fork do
          step.run
        end
        step.incoming && step.incoming.close
        step.outgoing && step.outgoing.close
      end

      Process.waitall
    end

    def to_s
      "#{self.class} with #{steps.length} steps"
    end

    private

    def prepare
      Rodimus.logger.info "Preparing #{self}..."
      # [1, 2, 3, 4] => [1, 2], [2, 3], [3, 4]
      steps.inject do |first, second|
        read, write = IO.pipe
        first.outgoing = write
        second.incoming = read
        second
      end
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rodimus-0.1.0 lib/rodimus/transformation.rb