Class: WickedPdf::Progress
- Inherits:
-
Object
- Object
- WickedPdf::Progress
- Defined in:
- lib/wicked_pdf/progress.rb
Instance Method Summary collapse
- #execute(command) ⇒ Object
-
#initialize(callback = nil) ⇒ Progress
constructor
A new instance of Progress.
Constructor Details
#initialize(callback = nil) ⇒ Progress
Returns a new instance of Progress.
6 7 8 |
# File 'lib/wicked_pdf/progress.rb', line 6 def initialize(callback = nil) @callback = callback end |
Instance Method Details
#execute(command) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/wicked_pdf/progress.rb', line 10 def execute(command) output = [] begin PTY.spawn(command.join(' ')) do |stdout, _stdin, pid| stdout.sync stdout.each_line("\r") do |line| output << line.chomp @callback.call(line) if @callback end rescue Errno::EIO # child process is terminated, this is expected behaviour ensure ::Process.wait pid end rescue PTY::ChildExited puts 'The child process exited!' end err = output.join('\n') raise "#{command} failed (exitstatus 0). Output was: #{err}" unless $CHILD_STATUS && $CHILD_STATUS.exitstatus.zero? end |