Class: Droonga::FileObserver

Inherits:
Object
  • Object
show all
Includes:
Changable, Loggable
Defined in:
lib/droonga/file_observer.rb

Constant Summary collapse

CHECK_INTERVAL =
1

Instance Method Summary collapse

Constructor Details

#initialize(loop, path) ⇒ FileObserver

Returns a new instance of FileObserver.



31
32
33
34
35
36
37
38
39
# 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
end

Instance Method Details

#startObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/droonga/file_observer.rb', line 41

def start
  return if @timer
  @timer = Coolio::TimerWatcher.new(CHECK_INTERVAL, true)
  @timer.on_timer do
    if updated?
      @mtime = @path.mtime
      on_change
    end
  end
  @loop.attach(@timer)
  logger.trace("start: timer attached",
               :watcher => @timer,
               :path    => @path)
end

#stopObject



56
57
58
59
60
61
62
# File 'lib/droonga/file_observer.rb', line 56

def stop
  @timer.detach if @timer
  logger.trace("stop: timer detached",
               :watcher => @timer,
               :path    => @path)
  @timer = nil
end