Class: DirWatcher
- Inherits:
-
Object
- Object
- DirWatcher
- Defined in:
- lib/dir_watcher.rb
Instance Method Summary collapse
-
#initialize(dir, options = {}, &block) ⇒ DirWatcher
constructor
A new instance of DirWatcher.
- #on_change ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(dir, options = {}, &block) ⇒ DirWatcher
Returns a new instance of DirWatcher.
4 5 6 7 8 9 |
# File 'lib/dir_watcher.rb', line 4 def initialize(dir, = {}, &block) @dir = dir @block = block @sleep_time = [:sleep_time] || 1 run end |
Instance Method Details
#on_change ⇒ Object
23 24 25 |
# File 'lib/dir_watcher.rb', line 23 def on_change @block.call end |
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dir_watcher.rb', line 11 def run while true new_run = `ls -lahRT #{@dir}` if new_run != @last_run on_change end @last_run = new_run sleep @sleep_time end end |