Build::Files::MonitorSourceBuildFilesMonitorNative

class Native

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 class Build::Files::Monitor::Polling but replaces the polling mechanism with native filesystem events.

Definitions

def run(**options, &block)

Run the monitor using native filesystem events.

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

Implementation

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

def run_roots(roots, **options, &block)

Monitor the specified roots for changes using native events.

Signature

parameter roots Array(String)

The root directories to monitor.

yields {...}

After each filesystem event.

returns Boolean

True if the set of monitored directories was updated.

Implementation

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