Sha256: 81ba0dc01cfb8fde014fa720ea0a9680314858cf7a3494f0067c8da9e7704606

Contents?: true

Size: 1.11 KB

Versions: 78

Compression:

Stored size: 1.11 KB

Contents

module RVM
  module Shell
    # Represents the output of a shell command.
    # This includes the exit status (and the helpful #successful? method)
    # as well accessors for the command and stdout / stderr.
    class Result

      attr_reader :command, :stdout, :stderr, :raw_status

      # Creates a new result object with the given details.
      def initialize(command, status, stdout, stderr)
        @command     = command.dup.freeze
        @raw_status  = status
        @environment = @raw_status["environment"] || {}
        @successful  = (exit_status == 0)
        @stdout      = stdout.freeze
        @stderr      = stderr.freeze
      end

      # Returns the hash of the environment.
      def env
        @environment
      end

      # Whether or not the command had a successful exit status.
      def successful?
        @successful
      end

      # Returns a value from the outputs environment.
      def [](key)
        env[key.to_s]
      end

      # Returns the exit status for the program
      def exit_status
        @exit_status ||= (Integer(@raw_status["exit_status"]) rescue 1)
      end

    end
  end
end

Version data entries

78 entries across 78 versions & 2 rubygems

Version Path
rvm-1.0.11 lib/rvm/shell/result.rb
rvm-1.0.10 lib/rvm/shell/result.rb
rvm-1.0.9 lib/rvm/shell/result.rb
rvm-1.0.8 lib/rvm/shell/result.rb
rvm-1.0.7 lib/rvm/shell/result.rb
rvm-1.0.6 lib/rvm/shell/result.rb
rvm-1.0.5 lib/rvm/shell/result.rb
rvm-1.0.4 lib/rvm/shell/result.rb
rvm-1.0.3 lib/rvm/shell/result.rb
rvm-1.0.2 lib/rvm/shell/result.rb
rvm-1.0.1 lib/rvm/shell/result.rb
rvm-1.0.0 lib/rvm/shell/result.rb
rvm-0.1.47 lib/rvm/shell/result.rb
rvm-0.1.46 lib/rvm/shell/result.rb
rvm-0.1.45 lib/rvm/shell/result.rb
rvm-0.1.44 lib/rvm/shell/result.rb
rvm-0.1.43 lib/rvm/shell/result.rb
rvm-0.1.42 lib/rvm/shell/result.rb