Sha256: 222a0119950a767ce9c24c19f2ff40792d3683e6d7813b81084e1f502f35b6f6

Contents?: true

Size: 1.01 KB

Versions: 6

Compression:

Stored size: 1.01 KB

Contents

module Boson
  module PipeRunner
    PIPE = '+'

    # Splits array into array of arrays with given element
    def self.split_array_by(arr, divider)
      arr.inject([[]]) {|results, element|
        (divider == element) ? (results << []) : (results.last << element)
        results
      }
    end

    def parse_args(args)
      @all_args = PipeRunner.split_array_by(args, PIPE)
      args = @all_args[0]
      super(args).tap do |result|
        @all_args[0] = ([result[0]] + Array(result[2])).compact
      end
    end

    def execute_command(command, args)
      @all_args.inject(nil) do |acc, (cmd,*args)|
        args = translate_args(args, acc)
        super(cmd, args)
      end
    end

    def translate_args(args, piped)
      args.unshift piped if piped
      args
    end

    # Commands to executed, in order given by user
    def commands
      @commands ||= @all_args.map {|e| e[0]}
    end
  end

  if defined? BinRunner
    class BinRunner < BareRunner
      class << self; include PipeRunner; end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
boson-more-0.3.1 lib/boson/pipe_runner.rb
boson-more-0.3.0 lib/boson/pipe_runner.rb
boson-more-0.2.2 lib/boson/pipe_runner.rb
boson-more-0.2.1 lib/boson/pipe_runner.rb
boson-more-0.2.0 lib/boson/pipe_runner.rb
boson-more-0.1.0 lib/boson/pipe_runner.rb