Class: Droonga::FileObserver
- Inherits:
-
Object
- Object
- Droonga::FileObserver
- Includes:
- Loggable
- Defined in:
- lib/droonga/file_observer.rb
Constant Summary collapse
- CHECK_INTERVAL =
1
Instance Attribute Summary collapse
-
#on_change ⇒ Object
Returns the value of attribute on_change.
Instance Method Summary collapse
-
#initialize(loop, path) ⇒ FileObserver
constructor
A new instance of FileObserver.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(loop, path) ⇒ FileObserver
Returns a new instance of FileObserver.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/droonga/file_observer.rb', line 31 def initialize(loop, path) @loop = loop @path = path if @path.exist? @mtime = @path.mtime else @mtime = nil end @on_change = nil end |
Instance Attribute Details
#on_change ⇒ Object
Returns the value of attribute on_change.
29 30 31 |
# File 'lib/droonga/file_observer.rb', line 29 def on_change @on_change end |
Instance Method Details
#start ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/droonga/file_observer.rb', line 42 def start @watcher = Coolio::TimerWatcher.new(CHECK_INTERVAL, true) on_timer = lambda do if updated? @mtime = @path.mtime @on_change.call if @on_change end end @watcher.on_timer do on_timer.call end @loop.attach(@watcher) end |
#stop ⇒ Object
56 57 58 |
# File 'lib/droonga/file_observer.rb', line 56 def stop @watcher.detach end |