Class: BoxGrinder::FSMonitor

Inherits:
Object
  • Object
show all
Includes:
Observable, Singleton
Defined in:
lib/boxgrinder-build/util/permissions/fs-monitor.rb

Instance Method Summary collapse

Constructor Details

#initializeFSMonitor

Returns a new instance of FSMonitor.



31
32
33
34
35
36
# 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

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.

Parameters:

  • Filesystem path.

Returns:

  • False if no observers were present.



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.

Parameters:

  • Observers to be notified of capture events. Each observer should expect a hash{} containing a :command, and potentially :data.

Yields:

  • Block that automatically calls #stop at the end of scope to cease capture.



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

#resetObject

Stop any capturing and delete all observers. Useful for testing.

See Also:



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

#stopObject

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

#triggerboolean

Trigger ownership change immediately, but without ceasing. Fires the :chown command on all observers.

Returns:

  • False if no observers were present.



95
96
97
98
# File 'lib/boxgrinder-build/util/permissions/fs-monitor.rb', line 95

def trigger
  changed(true)
  notify_observers(:command => :chown)
end