class RSpecLive::ConcurrentProcess
Public Class Methods
new(command)
click to toggle source
# File lib/rspec-live/concurrent_process.rb, line 5 def initialize(command) @command = command @output = "" end
Public Instance Methods
each_line() { |line| ... }
click to toggle source
# File lib/rspec-live/concurrent_process.rb, line 20 def each_line read_characters if running? shift_completed_lines.each_line { |line| yield line } end
running?()
click to toggle source
# File lib/rspec-live/concurrent_process.rb, line 10 def running? @running end
start()
click to toggle source
# File lib/rspec-live/concurrent_process.rb, line 14 def start @started_at = Time.now @stdout, @stdin, @pid = PTY.spawn @command @running = true end
Private Instance Methods
read_characters()
click to toggle source
# File lib/rspec-live/concurrent_process.rb, line 36 def read_characters while char = @stdout.read_nonblock(100000) @output << char end rescue IO::WaitReadable rescue Errno::EIO @stdout.close @stdin.close @running = false @duration = Time.now - @started_at end
shift_completed_lines()
click to toggle source
# File lib/rspec-live/concurrent_process.rb, line 27 def shift_completed_lines lines = "" while index = @output.index("\n") lines << @output.slice(0, index + 1) @output = @output.slice(index + 1, @output.length - index - 1) end lines end