Class: Droonga::FileObserver

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

Constant Summary collapse

CHECK_INTERVAL =
1

Instance Attribute Summary collapse

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
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_changeObject

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

#startObject



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

#stopObject



56
57
58
# File 'lib/droonga/file_observer.rb', line 56

def stop
  @watcher.detach
end