Class: Explorer::LogWatcher
- Inherits:
-
Object
- Object
- Explorer::LogWatcher
- Defined in:
- lib/explorer/log_watcher.rb
Instance Method Summary collapse
-
#add(watcher) ⇒ Object
TODO: terminate.
-
#initialize ⇒ LogWatcher
constructor
A new instance of LogWatcher.
- #log(label, line) ⇒ Object
- #remove(watcher) ⇒ Object
Constructor Details
#initialize ⇒ LogWatcher
Returns a new instance of LogWatcher.
3 4 5 6 |
# File 'lib/explorer/log_watcher.rb', line 3 def initialize @watchers = [] @mutex = Mutex.new end |
Instance Method Details
#add(watcher) ⇒ Object
TODO: terminate
10 11 12 13 14 |
# File 'lib/explorer/log_watcher.rb', line 10 def add(watcher) @mutex.synchronize do @watchers << watcher end end |
#log(label, line) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/explorer/log_watcher.rb', line 23 def log(label, line) @mutex.synchronize do @watchers.each do |watcher| begin watcher.puts "#{label}: #{line}" rescue remove(watcher) end end end end |
#remove(watcher) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/explorer/log_watcher.rb', line 16 def remove(watcher) @mutex.synchronize do @watcher.close @watchers.delete watcher end end |