# File lib/boxgrinder-build/util/permissions/fs-monitor.rb, line 31 def initialize @flag = GetSet.new @lock_a = Mutex.new @lock_b = Mutex.new set_hooks end
Add a path string. Called by the hooked methods when an applicable action
is triggered and capturing is enabled. Fires the :add_path
command, and includes the full path as :data
.
If no observers have been assigned before a path is added, they will be silently lost.
@param [String] path Filesystem path. @return [Boolean] False if no observers were present.
# File lib/boxgrinder-build/util/permissions/fs-monitor.rb, line 84 def add_path(path) @lock_b.synchronize do changed(true) notify_observers(:command => :add_path, :data => realpath(path)) end end
Start capturing paths. Providing a block automatically stops the capture process upon termination of the scope.
@param Array<update> Observers to be notified of capture
events. Each observer should expect a hash{} containing a +:command+, and potentially +:data+.
@yield Block that automatically calls stop at the end of scope
to cease capture.
# File lib/boxgrinder-build/util/permissions/fs-monitor.rb, line 47 def capture(*observers, &block) @lock_a.synchronize do add_observers(observers) _capture(&block) if block_given? yield _stop end end end
Stop any capturing and delete all observers. Useful for testing. @see stop
# File lib/boxgrinder-build/util/permissions/fs-monitor.rb, line 68 def reset @lock_a.synchronize do _stop delete_observers end end
Explicitly stop capturing paths. This should be utilised if capture was not
used with a block. Fires the :stop_capture
command to indicate
that capturing has ceased.
# File lib/boxgrinder-build/util/permissions/fs-monitor.rb, line 62 def stop @lock_a.synchronize { _stop } end
Trigger ownership change immediately, but without ceasing. Fires the
:chown
command on all observers.
@return [boolean] False if no observers were present.
# File lib/boxgrinder-build/util/permissions/fs-monitor.rb, line 95 def trigger changed(true) notify_observers(:command => :chown) end