Class: Starlined::Runner
- Inherits:
-
Object
- Object
- Starlined::Runner
- Defined in:
- lib/starlined/runner.rb
Instance Attribute Summary collapse
-
#animation ⇒ Object
readonly
Returns the value of attribute animation.
Instance Method Summary collapse
- #execute(callback, print_err: true, aka: nil, no_count: false, sudo: false) ⇒ Object
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #pass_step ⇒ Object
- #progress(aka: nil, no_count: false) ⇒ Object
- #run(command, print_err: true, aka: nil, no_count: false) ⇒ Object
- #start(message, steps: 0) ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
10 11 12 13 14 |
# File 'lib/starlined/runner.rb', line 10 def initialize @running_instances = 0 @run_semaphore = Mutex.new @animation = nil end |
Instance Attribute Details
#animation ⇒ Object (readonly)
Returns the value of attribute animation.
8 9 10 |
# File 'lib/starlined/runner.rb', line 8 def animation @animation end |
Instance Method Details
#execute(callback, print_err: true, aka: nil, no_count: false, sudo: false) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/starlined/runner.rb', line 51 def execute(callback, print_err: true, aka: nil, no_count: false, sudo: false) handle_sudo if sudo start_step(aka: aka) result = callback.call end_step(aka: aka, no_count: no_count) handle_error(result, print_err, aka) unless result.last.success? result end |
#pass_step ⇒ Object
47 48 49 |
# File 'lib/starlined/runner.rb', line 47 def pass_step @animation&.increment_step end |
#progress(aka: nil, no_count: false) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/starlined/runner.rb', line 40 def progress(aka: nil, no_count: false) start_step(aka: aka) yield ensure end_step(aka: aka, no_count: no_count) end |
#run(command, print_err: true, aka: nil, no_count: false) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/starlined/runner.rb', line 28 def run(command, print_err: true, aka: nil, no_count: false) needs_sudo = !!(command =~ /^sudo/) execute( -> { Open3.capture3(command) }, print_err: print_err, aka: aka, no_count: no_count, sudo: needs_sudo ) end |