Class: TestLauncher::Shell::Runner

Inherits:
Object
  • Object
show all
Includes:
Color
Defined in:
lib/test_launcher/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: "/dev/null") ⇒ Runner

Returns a new instance of Runner.



15
16
17
18
# File 'lib/test_launcher/shell/runner.rb', line 15

def initialize(log_path: "/dev/null")
  @log_path = log_path
  %x{echo "" > #{log_path}}
end

Instance Attribute Details

#log_path=(value) ⇒ Object

Sets the attribute log_path

Parameters:

  • value

    the value to set the attribute log_path to.



12
13
14
# File 'lib/test_launcher/shell/runner.rb', line 12

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.



12
13
14
# File 'lib/test_launcher/shell/runner.rb', line 12

def queue=(value)
  @queue = value
end

Instance Method Details

#confirm?(question) ⇒ Boolean

Returns:

  • (Boolean)


48
49
50
51
# File 'lib/test_launcher/shell/runner.rb', line 48

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

#exec(cmd) ⇒ Object



27
28
29
30
31
# File 'lib/test_launcher/shell/runner.rb', line 27

def exec(cmd)
  notify cmd
  $stdout.flush
  Kernel.exec cmd
end

#notify(msg) ⇒ Object



38
39
40
41
# File 'lib/test_launcher/shell/runner.rb', line 38

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

#puts(msg) ⇒ Object



43
44
45
46
# File 'lib/test_launcher/shell/runner.rb', line 43

def puts(msg)
  log msg
  print "#{msg}\n"
end

#run(cmd, dir: ".") ⇒ Object



20
21
22
23
24
25
# File 'lib/test_launcher/shell/runner.rb', line 20

def run(cmd, dir: ".")
  command = "cd #{dir} && #{cmd}"
  log(command)

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

#warn(msg) ⇒ Object



33
34
35
36
# File 'lib/test_launcher/shell/runner.rb', line 33

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