Class: FeatherWatch::Core::WindowsWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/feather_watch/core/windows_watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(directories, callback, verbose = false) ⇒ WindowsWatcher

Returns a new instance of WindowsWatcher.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/feather_watch/core/windows_watcher.rb', line 3

def initialize(directories, callback, verbose= false)
	@verbose = verbose
	puts "Initializing windows watcher" if @verbose
	@monitors = []
	directories.each do |dir|
		monitor = WDM::Monitor.new
		@monitors << monitor
		monitor.watch_recursively(dir, :files) do |change|
			#TODO: Have not tested this. It should work

			case change.type
			when :added, :renamed_new_file
				puts "File added: #{change.path}" if @verbose
				callback.call({status: :added, file: change.path})
			when :removed, :renamed_old_file
				puts "Removed file: #{change.path}" if @verbose
				callback.call({status: :removed, file: change.path})
			when :modified, :attrib
				puts "File modified: #{change.path}" if @verbose
				callback.call({status: :modified, file: change.path})
			else
				puts "Unhandled status type: #{change.type} for file #{change.path}" if @verbose
			end
		end	
	end
end

Instance Method Details

#startObject



30
31
32
33
34
35
36
37
# File 'lib/feather_watch/core/windows_watcher.rb', line 30

def start
	puts "Starting windows watcher" if @verbose
	@monitors.each do |monitor|
		Thread.new do
			monitor.run!
		end
	end
end

#stopObject



39
40
41
42
43
44
# File 'lib/feather_watch/core/windows_watcher.rb', line 39

def stop
	puts "Stopping windows watcher" if @verbose
	@monitors.each do |monitor|
		monitor.stop
	end
end