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.



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

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.



11
12
13
# File 'lib/test_launcher/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_launcher/shell/runner.rb', line 11

def queue=(value)
  @queue = value
end

Instance Method Details

#confirm?(question) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#exec(cmd) ⇒ Object



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

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

#notify(msg) ⇒ Object



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

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

#puts(msg) ⇒ Object



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

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

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



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

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

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

#warn(msg) ⇒ Object



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

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