Class: DuoSplitter::BatchProcessor
- Inherits:
-
Object
- Object
- DuoSplitter::BatchProcessor
- Defined in:
- lib/duo_splitter/batch_processor.rb
Instance Method Summary collapse
-
#initialize(message:, show_progress: true) ⇒ BatchProcessor
constructor
A new instance of BatchProcessor.
- #run(commands) ⇒ Object
Constructor Details
#initialize(message:, show_progress: true) ⇒ BatchProcessor
Returns a new instance of BatchProcessor.
7 8 9 10 |
# File 'lib/duo_splitter/batch_processor.rb', line 7 def initialize(message:, show_progress: true) = @show_progress = show_progress end |
Instance Method Details
#run(commands) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/duo_splitter/batch_processor.rb', line 12 def run(commands) commands.each.with_index(1) do |command, index| print_progress "#{@message} #{index}/#{commands.size}\r" shell_output = IO.popen(command, err: i[child out], &:read) status = $CHILD_STATUS.exitstatus unless status.zero? print_progress "\n" print_progress "#{shell_output}\n" raise Error, "process exit with #{status}" end end print_progress "\n" end |