Module: CreateGithubRelease::BacktickDebug

Included in:
AssertionBase, Project, TaskBase
Defined in:
lib/create_github_release/backtick_debug.rb

Overview

Include this module to output debug information for backticks

The class this module is included in must have a backtick_debug? method.

Examples:

Using this module to debug backticks

class Foo
  include CreateGithubRelease::BacktickDebug

  def backtick_debug?; true; end

  def bar
    `echo foo`
  end
end

Foo.new.bar #=>
COMMAND
  echo foo
OUTPUT
  foo
EXITSTATUS
  0

Instance Method Summary collapse

Instance Method Details

#`(command) ⇒ String

Calls super and shows the command and its result if backtick_debug? is true

The command, it's output, and it's exit status are output to stdout via puts.

The including class is expected to have a backtick_debug? method.

Examples:

including_class.new.send('`'.to_sym, 'echo foo') #=>
 COMMAND
   echo foo
 OUTPUT
   foo
 EXITSTATUS
   0

A command that fails

including_class.new.send('`'.to_sym, 'echo foo; exit 1') #=>
 COMMAND
   echo foo
 OUTPUT
   foo
 EXITSTATUS
   1

Parameters:

  • command (String)

    the command to execute

Returns:

  • (String)

    the output of the command



58
59
60
61
62
63
64
65
66
67
# File 'lib/create_github_release/backtick_debug.rb', line 58

def `(command)
  puts "COMMAND\n  #{command}" if backtick_debug?
  super.tap do |output|
    if backtick_debug?
      puts "OUTPUT\n"
      output.lines { |l| puts "  #{l.chomp}" }
      puts "EXITSTATUS\n  #{$CHILD_STATUS.exitstatus}\n"
    end
  end
end