Class: BoxGrinder::FSMonitor
- Inherits:
-
Object
- Object
- BoxGrinder::FSMonitor
- Includes:
- Observable, Singleton
- Defined in:
- lib/boxgrinder-build/util/permissions/fs-monitor.rb
Instance Method Summary collapse
-
#add_path(path) ⇒ Boolean
Add a path string.
-
#capture(*observers) { ... } ⇒ Object
Start capturing paths.
-
#initialize ⇒ FSMonitor
constructor
A new instance of FSMonitor.
-
#reset ⇒ Object
Stop any capturing and delete all observers.
-
#stop ⇒ Object
Explicitly stop capturing paths.
-
#trigger ⇒ boolean
Trigger ownership change immediately, but without ceasing.
Constructor Details
Instance Method Details
#add_path(path) ⇒ Boolean
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.
84 85 86 87 88 89 |
# 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 |
#capture(*observers) { ... } ⇒ Object
Start capturing paths. Providing a block automatically stops the capture process upon termination of the scope.
47 48 49 50 51 52 53 54 55 56 57 |
# 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 |
#reset ⇒ Object
Stop any capturing and delete all observers. Useful for testing.
68 69 70 71 72 73 |
# File 'lib/boxgrinder-build/util/permissions/fs-monitor.rb', line 68 def reset @lock_a.synchronize do _stop delete_observers end end |
#stop ⇒ Object
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.
62 63 64 |
# File 'lib/boxgrinder-build/util/permissions/fs-monitor.rb', line 62 def stop @lock_a.synchronize { _stop } end |
#trigger ⇒ boolean
Trigger ownership change immediately, but without ceasing. Fires
the :chown command on all observers.
95 96 97 98 |
# File 'lib/boxgrinder-build/util/permissions/fs-monitor.rb', line 95 def trigger changed(true) notify_observers(:command => :chown) end |