Class: Pazuzu::Utility::OutputTailer
- Inherits:
-
Object
- Object
- Pazuzu::Utility::OutputTailer
- Defined in:
- lib/pazuzu/utility/output_tailer.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(options = {}) ⇒ OutputTailer
constructor
A new instance of OutputTailer.
- #open ⇒ Object
- #tail! ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ OutputTailer
Returns a new instance of OutputTailer.
6 7 8 9 10 11 12 |
# File 'lib/pazuzu/utility/output_tailer.rb', line 6 def initialize( = {}) @limit = [:limit] || 1000 @callback = [:on_line] || proc { } @mutex = Mutex.new @buffer = '' @entries = [] end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
45 46 47 |
# File 'lib/pazuzu/utility/output_tailer.rb', line 45 def entries @entries end |
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
46 47 48 |
# File 'lib/pazuzu/utility/output_tailer.rb', line 46 def limit @limit end |
Instance Method Details
#close ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/pazuzu/utility/output_tailer.rb', line 21 def close if @stream @stream.close rescue nil @stream = nil end if @thread @thread.terminate @thread = nil end end |
#open ⇒ Object
14 15 16 17 18 19 |
# File 'lib/pazuzu/utility/output_tailer.rb', line 14 def open close @stream, writeable_stream = IO.pipe @thread = Thread.start { tail! } return writeable_stream end |
#tail! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/pazuzu/utility/output_tailer.rb', line 32 def tail! while @stream data = @stream.readpartial(4096) @mutex.synchronize do @buffer << data while @buffer =~ /\A([^\r\n]*)\r?\n(.*)/ @buffer = $2 add_line!($1) end end end end |