Sha256: a4fb5202f554673782cd660f44459072e59501bd2ff61a72cc31ee168c525e0b

Contents?: true

Size: 1.14 KB

Versions: 29

Compression:

Stored size: 1.14 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 ? (@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

29 entries across 29 versions & 1 rubygems

Version Path
rvm-1.11.3.9 lib/rvm/shell/result.rb
rvm-1.11.3.8 lib/rvm/shell/result.rb
rvm-1.11.3.7 lib/rvm/shell/result.rb
rvm-1.11.3.6 lib/rvm/shell/result.rb
rvm-1.11.3.5 lib/rvm/shell/result.rb
rvm-1.11.3.4 lib/rvm/shell/result.rb
rvm-1.11.3.3 lib/rvm/shell/result.rb
rvm-1.11.3.2 lib/rvm/shell/result.rb
rvm-1.11.3.1 lib/rvm/shell/result.rb
rvm-1.11.3 lib/rvm/shell/result.rb
rvm-1.9.2 lib/rvm/shell/result.rb
rvm-1.9.1 lib/rvm/shell/result.rb
rvm-1.9.0 lib/rvm/shell/result.rb
rvm-1.8.6 lib/rvm/shell/result.rb
rvm-1.8.5 lib/rvm/shell/result.rb
rvm-1.8.4 lib/rvm/shell/result.rb
rvm-1.8.3 lib/rvm/shell/result.rb
rvm-1.8.2 lib/rvm/shell/result.rb
rvm-1.8.1 lib/rvm/shell/result.rb
rvm-1.7.0 lib/rvm/shell/result.rb