Class: Chef::Resolver::FileWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/resolver/file_watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(filenames) ⇒ FileWatcher

Returns a new instance of FileWatcher.



4
5
6
# File 'lib/chef/resolver/file_watcher.rb', line 4

def initialize filenames
  self.filenames = filenames
end

Instance Method Details

#filenames=(filenames) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/chef/resolver/file_watcher.rb', line 8

def filenames= filenames
  @filenames = filenames || []
  @mtimes = {}
  @filenames.each do |f|
    raise "File does not exist: #{f}" unless File.exist?(f)
    @mtimes[f] = File.stat(f).mtime
  end
end

#stopObject



21
22
23
# File 'lib/chef/resolver/file_watcher.rb', line 21

def stop
  @thread.kill
end

#watch(&callback) ⇒ Object



17
18
19
# File 'lib/chef/resolver/file_watcher.rb', line 17

def watch &callback
  @thread = Thread.new { watch_filenames &callback }
end