Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 37 lines (30 sloc) 0.744 kb
1fd9d97 @wycats Add initial FileWatcher implementation. The Backend is just an abstract ...
wycats authored
1 module ActiveSupport
2 class FileWatcher
3 class Backend
4 def initialize(path, watcher)
5 @watcher = watcher
6 @path = path
7 end
8
9 def trigger(files)
10 @watcher.trigger(files)
11 end
12 end
13
14 def initialize
15 @regex_matchers = {}
16 end
17
51414a0 @tenderlove use === so that regular expressions are not required
tenderlove authored
18 def watch(pattern, &block)
19 @regex_matchers[pattern] = block
1fd9d97 @wycats Add initial FileWatcher implementation. The Backend is just an abstract ...
wycats authored
20 end
21
22 def trigger(files)
23 trigger_files = Hash.new { |h,k| h[k] = Hash.new { |h2,k2| h2[k2] = [] } }
24
25 files.each do |file, state|
51414a0 @tenderlove use === so that regular expressions are not required
tenderlove authored
26 @regex_matchers.each do |pattern, block|
27 trigger_files[block][state] << file if pattern === file
1fd9d97 @wycats Add initial FileWatcher implementation. The Backend is just an abstract ...
wycats authored
28 end
29 end
30
31 trigger_files.each do |block, payload|
32 block.call payload
33 end
34 end
35 end
36 end
Something went wrong with that request. Please try again.