Class: PluginTool::WatcherPoll

Inherits:
Object
  • Object
show all
Defined in:
lib/watchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(dirs) ⇒ WatcherPoll

Returns a new instance of WatcherPoll.



11
12
13
14
# File 'lib/watchers.rb', line 11

def initialize(dirs)
  @dirs = dirs
  @last_contents = make_contents
end

Instance Method Details

#make_contentsObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/watchers.rb', line 26

def make_contents
  c = ''
  @dirs.each do |dir|
    Dir.glob("#{dir}/**/*").each do |file|
      c << file
      c << ":#{File.mtime(file).to_i}\n"
    end
  end
  c
end

#wait(timeout) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/watchers.rb', line 15

def wait(timeout)
  while timeout > 0
    c = make_contents
    if @last_contents != c
      @last_contents = c
      return
    end
    timeout -= 1
    sleep 1
  end
end