Sha256: e967a1ce7c3e2e44a6ea82ed0ae65f4fac862f1e876c99206c2ef69511beae3c

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

module PredragsDummyPipelines

  class Exec
    attr_reader :name
    attr_reader :cmd
    attr_reader :test

    def initialize(actions, name)
      @name = name
      @cmd  = actions["cmd"]  || []
      @test = actions["test"] || []
      @cmd_results = []
      @test_results = []
    end

    def run
      run_cmd(@cmd, @cmd_results, true)
      return if not success_impl(@cmd_results)
      run_cmd(@test, @test_results, false)
    end

    def show
      [{exec_name: @name}, @cmd_results, @test_results]
    end

    def results
      {:cmd => @cmd_results, :test => @test_results, name: @name}
    end

    def success?
      success_impl(@cmd_results) and success_impl(@test_results)
    end

    def success_impl(results)
      return false if (results == [])
      results.each {|cmd| cmd[:estatus]}.all? {|status| status == 0}
    end

    private

    def run_cmd(commands, results, should_break)
      commands.each {|c|
        begin
          results << {:input => c, :output => %x[#{c}] || "", :estatus => $?.exitstatus}
          break if should_break and $?.exitstatus != 0
        rescue => e
          results << {:input => c, :output => e.inspect, :estatus => $?.exitstatus}
          break if should_break
        end
      }
      @results
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
predrags_dummy_pipelines-0.8.3 lib/predrags_dummy_pipelines/exec.rb