Class: RubyGit::CommandLine::Result

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/ruby_git/command_line/result.rb

Overview

The result of running a git command

Adds stdout and stderr processing to the ProcessExecuter::Result class.

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ RubyGit::CommandLine::Result

Initialize a new result object

Examples:

result = ProcessExecuter.run('echo hello')
RubyGit::CommandLine::Result.new(result)

Parameters:

  • result (ProcessExecuter::Result)

    The result of running the command



# File 'lib/ruby_git/command_line/result.rb', line 15


Instance Method Details

#process_stderr {|stderr, result| ... } ⇒ String?

Process the captured stderr output

Examples:

result = ProcessExecuter.run('echo hello 1>&2', err: StringIO.new)
result.stderr #=> "hello\n"
result.process_stderr { |stderr, _result| stderr.upcase }
result.stderr #=> "HELLO\n"
result.unprocessed_stderr #=> "hello\n"

Chain processing

result = ProcessExecuter.run('echo hello 1>&2', err: StringIO.new)
result.stderr #=> "hello\n"
result.process_stderr { |s| s.upcase }.process_stderr { |s| s.reverse }
result.stderr #=> "OLLEH\n"
result.unprocessed_stderr #=> "hello\n"

Yields:

  • (stderr, result)

    Yields the stderr output and the result object

Yield Parameters:

Yield Returns:

  • (String)

    The processed stderr output

Returns:

  • (String, nil)


129
130
131
132
133
134
# File 'lib/ruby_git/command_line/result.rb', line 129

def process_stderr(&block)
  return if block.nil?

  @processed_stderr = block.call(stderr, self)
  self
end

#process_stdout {|stdout, result| ... } ⇒ String?

Process the captured stdout output

Examples:

result = ProcessExecuter.run('echo hello', out: StringIO.new)
result.stdout #=> "hello\n"
result.process_stdout { |stdout, _result| stdout.upcase }
result.stdout #=> "HELLO\n"
result.unprocessed_stdout #=> "hello\n"

Chain processing

result = ProcessExecuter.run('echo hello', out: StringIO.new)
result.stdout #=> "hello\n"
result.process_stdout { |s| s.upcase }.process_stdout { |s| s.reverse }
result.stdout #=> "OLLEH\n"
result.unprocessed_stdout #=> "hello\n"

Yields:

  • (stdout, result)

    Yields the stdout output and the result object

Yield Parameters:

Yield Returns:

  • (String)

    The processed stdout output

Returns:

  • (String, nil)


64
65
66
67
68
69
# File 'lib/ruby_git/command_line/result.rb', line 64

def process_stdout(&block)
  return if block.nil?

  @processed_stdout = block.call(stdout, self)
  self
end

#stderrString?

Return the processed stderr output (or original if it was not processed)

This output is only returned if a stderr redirection is a ProcessExecuter::MonitoredPipe.

Examples:

result = ProcessExecuter.run('echo hello 1>&2': err: StringIO.new)
result.stderr #=> "hello\n"

Returns:

  • (String, nil)


100
101
102
# File 'lib/ruby_git/command_line/result.rb', line 100

def stderr
  defined?(@processed_stderr) ? @processed_stderr : unprocessed_stderr
end

#stdoutString?

Return the processed stdout output (or original if it was not processed)

This output is only returned if a stdout redirection is a ProcessExecuter::MonitoredPipe.

Examples:

result = ProcessExecuter.run('echo hello': out: StringIO.new)
result.stdout #=> "hello\n"

Returns:

  • (String, nil)


35
36
37
# File 'lib/ruby_git/command_line/result.rb', line 35

def stdout
  defined?(@processed_stdout) ? @processed_stdout : unprocessed_stdout
end

#unprocessed_stderrString?

Returns the original stderr output before it was processed

Examples:

result = ProcessExecuter.run('echo hello 1>&2', err: StringIO.new)
result.stderr #=> "hello\n"
result.unprocessed_stderr #=> "hello\n"
result.process_stderr { |stderr| stderr.upcase }
result.stderr #=> "HELLO\n"
result.unprocessed_stderr #=> "hello\n"

Returns:

  • (String, nil)


150
151
152
# File 'lib/ruby_git/command_line/result.rb', line 150

def unprocessed_stderr
  __getobj__.stderr
end

#unprocessed_stdoutString?

Returns the original stdout output before it was processed

Examples:

result = ProcessExecuter.run('echo hello', out: StringIO.new)
result.stdout #=> "hello\n"
result.unprocessed_stdout #=> "hello\n"
result.process_stdout { |s| s.upcase }
result.stdout #=> "HELLO\n"
result.unprocessed_stdout #=> "hello\n"

Returns:

  • (String, nil)


85
86
87
# File 'lib/ruby_git/command_line/result.rb', line 85

def unprocessed_stdout
  __getobj__.stdout
end