Class: MCLib::Watcher
- Inherits:
-
Object
- Object
- MCLib::Watcher
- Includes:
- EventMapper
- Defined in:
- lib/mclib/watcher.rb
Instance Attribute Summary collapse
-
#watch_thread ⇒ Object
Returns the value of attribute watch_thread.
Instance Method Summary collapse
-
#initialize(mc_dir = nil) ⇒ Watcher
constructor
A new instance of Watcher.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(mc_dir = nil) ⇒ Watcher
Returns a new instance of Watcher.
12 13 14 15 16 17 18 19 20 |
# File 'lib/mclib/watcher.rb', line 12 def initialize(mc_dir = nil) if mc_dir.nil? mc_dir = MCLib::get_mc_dir end @log_file = mc_dir + '/logs/latest.log' @log_watcher = FileWatch::Tail.new @parser = MCLib::LogParser.new end |
Instance Attribute Details
#watch_thread ⇒ Object
Returns the value of attribute watch_thread.
10 11 12 |
# File 'lib/mclib/watcher.rb', line 10 def watch_thread @watch_thread end |
Instance Method Details
#start ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mclib/watcher.rb', line 22 def start @watch_thread = Thread.new do @log_watcher.tail @log_file @log_watcher.subscribe do |path, line| if !line.empty? && !line.nil? event = @parser.parse line # fire the event with the correct event handler api parameters delegate_parameters event # always fire the :all handlers fire :all, event end end end end |
#stop ⇒ Object
39 40 41 |
# File 'lib/mclib/watcher.rb', line 39 def stop @watch_thread.kill end |