Sha256: 28fec9e64eb1bde49fa9ece35647287bf256801806e14c5f5ed46907aa847526

Contents?: true

Size: 1.3 KB

Versions: 25

Compression:

Stored size: 1.3 KB

Contents

module Methadone
  # <b>Methadone Internal - treat as private</b>
  #
  # A wrapper/enhancement of Process::Status that handles coersion and expected
  # nonzero statuses
  class ProcessStatus

    # The exit status, either directly from a Process::Status or derived from a non-Int value.
    attr_reader :exitstatus

    # Create the ProcessStatus with the given status.
    #
    # status:: if this responds to #exitstatus, that method is used to extract the exit code.  If it's
    #          and Int, that is used as the exit code.  Otherwise,
    #          it's truthiness is used: 0 for truthy, 1 for falsey.
    # expected:: an Int or Array of Int representing the expected exit status, other than zero,
    #            that represent "success".
    def initialize(status,expected)
      @exitstatus = derive_exitstatus(status)
      @success = ([0] + Array(expected)).include?(@exitstatus)
    end

    # True if the exit status was a successul (i.e. expected) one.
    def success?
      @success
    end

  private

    def derive_exitstatus(status)
      status = if status.respond_to? :exitstatus
                 status.exitstatus
               else
                 status
               end
      if status.kind_of? Fixnum
        status
      elsif status
        0
      else
        1
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 2 rubygems

Version Path
methadone-1.2.1 lib/methadone/process_status.rb
methadone-1.2.0 lib/methadone/process_status.rb
methadone-1.1.0 lib/methadone/process_status.rb
methadone-1.0.0 lib/methadone/process_status.rb
methadone-1.0.0.rc6 lib/methadone/process_status.rb