Class: FeatherWatch::Core::DarwinWatcher

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of DarwinWatcher.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/feather_watch/core/darwin_watcher.rb', line 3

def initialize(directories, callback, verbose= false)
	@verbose = verbose
	puts "Initializing mac watcher" if @verbose
	@fs_event = FSEvent.new
	options = { :no_defer => true,
				:file_events => true }

	@fs_event.watch directories, options do |changed_files|
		changed_files.each do |f|
			if File.file?(f)
				puts "Change on file: #{f}" if @verbose
				callback.call({status: :modified, file: f})
			else
				puts "Removed file: #{f}" if @verbose
				callback.call({status: :removed, file: f})
			end
		end
	end
end

Instance Method Details

#startObject



23
24
25
26
27
28
# File 'lib/feather_watch/core/darwin_watcher.rb', line 23

def start
	puts "Starting mac watcher" if @verbose
	Thread.new do
		@fs_event.run
	end
end

#stopObject



30
31
32
33
# File 'lib/feather_watch/core/darwin_watcher.rb', line 30

def stop
	puts "Stopping mac watcher" if @verbose
	@fs_event.stop
end