Class: Pwrake::Writer
- Inherits:
-
Object
- Object
- Pwrake::Writer
- Includes:
- Singleton
- Defined in:
- lib/pwrake/worker/writer.rb
Instance Method Summary collapse
- #add_logger(log) ⇒ Object
- #dputs(s) ⇒ Object
- #flush ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #print(s) ⇒ Object
- #puts(s) ⇒ Object
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/pwrake/worker/writer.rb', line 8 def initialize @out = $stdout @mutex = Mutex.new pipe_in, pipe_out = IO.pipe Thread.new(pipe_in,"log:") do |pin,pre| while s = pin.gets s.chomp! @out.puts pre+s end end $stderr = pipe_out end |
Instance Method Details
#add_logger(log) ⇒ Object
21 22 23 |
# File 'lib/pwrake/worker/writer.rb', line 21 def add_logger(log) @log = log end |
#dputs(s) ⇒ Object
54 55 56 |
# File 'lib/pwrake/worker/writer.rb', line 54 def dputs(s) puts(s) if $DEBUG end |
#flush ⇒ Object
47 48 49 50 51 52 |
# File 'lib/pwrake/worker/writer.rb', line 47 def flush begin @out.flush rescue end end |
#print(s) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pwrake/worker/writer.rb', line 36 def print(s) begin @mutex.synchronize do @out.print s end @out.flush rescue Errno::EPIPE end @log.info "<#{s}" if @log end |
#puts(s) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/pwrake/worker/writer.rb', line 25 def puts(s) begin @mutex.synchronize do @out.print s+"\n" end @out.flush rescue Errno::EPIPE end @log.info "<#{s}" if @log end |