Sha256: ad022a9ab0bcaef60714c29688cb8b4bde26ab74ec382e3aa92f24f7df559f41

Contents?: true

Size: 1.26 KB

Versions: 16

Compression:

Stored size: 1.26 KB

Contents

module QueueDispatcher
  class RcAndMsg
    attr_accessor :rc, :output, :error_msg


    def self.good_rc(output = '', args = {})
      rc_and_msg = new
      rc_and_msg.good_rc(output, args)
    end


    def self.bad_rc(error_msg, args = {})
      rc_and_msg = new
      rc_and_msg.bad_rc(error_msg, args)
    end


    # Initializer
    def initialize(args = {})
      @rc = args[:rc].to_i if args[:rc]
      @output = args[:output]
      @error_msg = args[:error_msg]
      self
    end


    # Fake a good RC
    def good_rc(output = '', args = {})
      @rc = 0
      @output = output
      @error_msg = args[:error_msg]
      self
    end


    # Fake a bad RC
    def bad_rc(error_msg = '', args = {})
      @rc = 999
      @output = args[:output]
      @error_msg = error_msg
      self
    end


    # Addition
    def +(other)
      rc_and_msg = self.clone
      rc_and_msg.rc += other.rc
      rc_and_msg.output = rc_and_msg.output ? "#{output}\n#{other.output}" : other.output if other.output.present?
      rc_and_msg.error_msg = rc_and_msg.error_msg ? "#{error_msg}\n#{other.error_msg}" : other.error_msg if other.error_msg.present?
      rc_and_msg
    end


    # Return hash
    def to_hash
      { :rc => @rc, :output => @output, :error_msg => @error_msg }
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
queue_dispatcher-2.5.3 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-2.3.0 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-2.1.0 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.5.1 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.3.1 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.3.0 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.2.0 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.19 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.18 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.17 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.16 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.15 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.14 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.12 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.11 lib/queue_dispatcher/rc_and_msg.rb
queue_dispatcher-1.1.10 lib/queue_dispatcher/rc_and_msg.rb