Class: TestRun::Shell::Runner
- Inherits:
-
Object
- Object
- TestRun::Shell::Runner
- Includes:
- Color
- Defined in:
- lib/test_run/shell/runner.rb
Constant Summary collapse
- CommandFailureError =
Class.new(StandardError)
Constants included from Color
Instance Attribute Summary collapse
-
#log_path ⇒ Object
writeonly
Sets the attribute log_path.
-
#queue ⇒ Object
writeonly
Sets the attribute queue.
-
#working_directory ⇒ Object
writeonly
Sets the attribute working_directory.
Instance Method Summary collapse
- #confirm?(question) ⇒ Boolean
- #exec(cmd) ⇒ Object
-
#initialize(log_path:, working_directory:) ⇒ Runner
constructor
A new instance of Runner.
- #notify(msg) ⇒ Object
- #run(cmd, dir: working_directory, &block) ⇒ Object
- #warn(msg) ⇒ Object
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
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
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
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
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 |