Class: TestRun::Shell::Runner

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/test_run/shell/runner.rb

Constant Summary collapse

CommandFailureError =
Class.new(StandardError)

Constants included from Color

Color::CODES

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(log_path:, working_directory:) ⇒ Runner

Returns a new instance of Runner.



14
15
16
17
18
19
20
# File 'lib/test_run/shell/runner.rb', line 14

def initialize(log_path:, working_directory:)
  @working_directory = working_directory
  @log_path = log_path

  %x{echo "" > #{log_path}}
  Dir.chdir(%x[ git rev-parse --show-toplevel ].chomp)
end

Instance Attribute Details

#log_path=(value) ⇒ Object

Sets the attribute log_path

Parameters:

  • value

    the value to set the attribute log_path to.



11
12
13
# File 'lib/test_run/shell/runner.rb', line 11

def log_path=(value)
  @log_path = value
end

#queue=(value) ⇒ Object

Sets the attribute queue

Parameters:

  • value

    the value to set the attribute queue to.



11
12
13
# File 'lib/test_run/shell/runner.rb', line 11

def queue=(value)
  @queue = value
end

#working_directory=(value) ⇒ Object

Sets the attribute working_directory

Parameters:

  • value

    the value to set the attribute working_directory to.



11
12
13
# File 'lib/test_run/shell/runner.rb', line 11

def working_directory=(value)
  @working_directory = value
end

Instance Method Details

#confirm?(question) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
# File 'lib/test_run/shell/runner.rb', line 44

def confirm?(question)
  warn "#{question} [Yn]"
  answer = STDIN.gets.strip.downcase
  return answer != 'n'
end

#exec(cmd) ⇒ Object



29
30
31
32
# File 'lib/test_run/shell/runner.rb', line 29

def exec(cmd)
  notify cmd
  Kernel.exec cmd
end

#notify(msg) ⇒ Object



39
40
41
42
# File 'lib/test_run/shell/runner.rb', line 39

def notify(msg)
  log msg.to_s
  print "#{yellow(msg.to_s)}\n"
end

#run(cmd, dir: working_directory, &block) ⇒ Object



22
23
24
25
26
27
# File 'lib/test_run/shell/runner.rb', line 22

def run(cmd, dir: working_directory, &block)
  command = "cd #{Utils::Path.relative_join(dir)} && #{cmd}"
  handle_output_for(command)

  shell_out(command).split("\n")
end

#warn(msg) ⇒ Object



34
35
36
37
# File 'lib/test_run/shell/runner.rb', line 34

def warn(msg)
  log msg.to_s
  print "#{red(msg.to_s)}\n"
end