class Handle
Represents a tracked set of files with an associated callback.
A handle is created when you call Build::Files::Monitor::Polling#track_changes
and connects a set of files to a callback block that fires when changes are detected. The handle maintains the state of monitored files and can be removed from the monitor when no longer needed.
Definitions
def initialize(monitor, files, &block)
Initialize a new handle.
Signature
-
parameter
monitor
Polling
The monitor that owns this handle.
-
parameter
files
List
The list of files to track.
-
parameter
block
Proc
The callback to invoke when changes are detected.
Implementation
def initialize(monitor, files, &block)
@monitor = monitor
@state = State.new(files)
@block = block
end
attr :monitor
Signature
-
attribute
Polling
The monitor that owns this handle.
def commit!
Update the internal state of tracked files.
This method forces an update of the file state without invoking the callback.
Implementation
def commit!
@state.update!
end
def directories
Signature
-
returns
Array(Path)
The root directories being monitored by this handle.
Implementation
def directories
@state.files.roots
end
def remove!
Remove this handle from the monitor.
After calling this method, the callback will no longer be invoked when changes are detected.
Implementation
def remove!
@monitor.delete(self)
end
def changed!
Inform the handle that it might have been modified.
Implementation
def changed!
# If @state.update! did not find any changes, don't invoke the callback:
if @state.update!
@block.call(@state)
end
end
def to_s
Signature
-
returns
String
A string representation of the handle.
Implementation
def to_s
"\#<#{self.class} @state=#{@state} @block=#{@block}>"
end