lib/cmds/io_handler.rb in cmds-0.2.4 vs lib/cmds/io_handler.rb in cmds-0.2.5
- old
+ new
@@ -1,15 +1,24 @@
class Cmds
class IOHandler
attr_accessor :in, :out, :err
def initialize
- @queue = Queue.new
@in = nil
@out = $stdout
@err = $stderr
end
+
+ def out= value
+ value = value.to_s if value.is_a? Pathname
+ @out = value
+ end
+
+ def err= value
+ value = value.to_s if value.is_a? Pathname
+ @err = value
+ end
def on_out &block
@out = block
end
@@ -30,10 +39,14 @@
def thread_send_line sym, line
@queue << [sym, line]
end
def start
+ # Initialize a thread-safe queue for passing output from the IO threads
+ # back to the main thread
+ @queue = Queue.new
+
# if out is a proc, it's not done
out_done = ! @out.is_a?(Proc)
# same for err
err_done = ! @err.is_a?(Proc)
@@ -71,6 +84,6 @@
end
end
# end private
end # end IOHandler
-end # class Cmds
\ No newline at end of file
+end # class Cmds