Class: Build::Files::Monitor::Native

Inherits:
Polling
  • Object
show all
Defined in:
lib/build/files/monitor/native.rb

Overview

A platform-specific filesystem monitor using native OS APIs.

This implementation uses platform-specific APIs (FSEvent on macOS, INotify on Linux) for efficient, event-driven file monitoring. It extends Polling but replaces the polling mechanism with native filesystem events.

Instance Attribute Summary

Attributes inherited from Polling

#updated

Instance Method Summary collapse

Methods inherited from Polling

#Whether the set of monitored directories has been updated.=, #add, #delete, #initialize, #roots, #track_changes, #update

Constructor Details

This class inherits a constructor from Build::Files::Monitor::Polling

Instance Method Details

#run(**options, &block) ⇒ Object

Run the monitor using native filesystem events.

This method blocks until interrupted via ‘throw :interrupt`. Unlike Polling#run, this uses native OS events rather than polling.



21
22
23
24
25
26
27
# File 'lib/build/files/monitor/native.rb', line 21

def run(**options, &block)
	catch(:interrupt) do
		while true
			run_roots(self.roots, **options, &block)
		end
	end
end

#run_roots(roots, **options, &block) ⇒ Object

Monitor the specified roots for changes using native events.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/build/files/monitor/native.rb', line 34

def run_roots(roots, **options, &block)
	monitor = IO::Watch::Monitor.new(self.roots, **options)
	
	monitor.run do |event|
		if root = event[:root]
			self.update([root])
			
			yield if block_given?
			
			if self.updated
				return true
			end
		end
	end
	
	return false
end