Class: Build::Files::Monitor::Polling
- Inherits:
-
Object
- Object
- Build::Files::Monitor::Polling
- Defined in:
- lib/build/files/monitor/polling.rb
Instance Attribute Summary collapse
-
#updated ⇒ Object
readonly
Returns the value of attribute updated.
Instance Method Summary collapse
- #add(handle) ⇒ Object
- #delete(handle) ⇒ Object
-
#initialize(logger: nil) ⇒ Polling
constructor
A new instance of Polling.
- #roots ⇒ Object
- #run(**options, &block) ⇒ Object
- #track_changes(files, &block) ⇒ Object
-
#update(directories, *args) ⇒ Object
Notify the monitor that files in these directories have changed.
Constructor Details
#initialize(logger: nil) ⇒ Polling
Returns a new instance of Polling.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/build/files/monitor/polling.rb', line 30 def initialize(logger: nil) @directories = Hash.new do |hash, key| hash[key] = Set.new end @updated = false @deletions = nil @logger = logger || Logger.new(nil) end |
Instance Attribute Details
#updated ⇒ Object (readonly)
Returns the value of attribute updated.
42 43 44 |
# File 'lib/build/files/monitor/polling.rb', line 42 def updated @updated end |
Instance Method Details
#add(handle) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/build/files/monitor/polling.rb', line 81 def add(handle) @logger.debug{"Adding handle: #{handle}"} handle.directories.each do |directory| # We want the full path as a plain string: directory = directory.to_s @directories[directory] << handle # We just added the first handle: if @directories[directory].size == 1 # If the handle already existed, this might trigger unnecessarily. @updated = true end end handle end |
#delete(handle) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/build/files/monitor/polling.rb', line 66 def delete(handle) if @deletions @logger.debug{"Delayed delete handle: #{handle}"} @deletions << handle else purge(handle) end end |
#roots ⇒ Object
62 63 64 |
# File 'lib/build/files/monitor/polling.rb', line 62 def roots @directories.keys end |
#run(**options, &block) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/build/files/monitor/polling.rb', line 100 def run(**, &block) catch(:interrupt) do while true monitor.update(monitor.roots) yield sleep([:latency] || 1.0) end end end |
#track_changes(files, &block) ⇒ Object
75 76 77 78 79 |
# File 'lib/build/files/monitor/polling.rb', line 75 def track_changes(files, &block) handle = Handle.new(self, files, &block) add(handle) end |
#update(directories, *args) ⇒ Object
Notify the monitor that files in these directories have changed.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/build/files/monitor/polling.rb', line 45 def update(directories, *args) @logger.debug{"Update: #{directories} #{args.inspect}"} delay_deletions do directories.each do |directory| @logger.debug{"Directory: #{directory}"} @directories[directory].each do |handle| @logger.debug{"Handle changed: #{handle.inspect}"} # Changes here may not actually require an update to the handle: handle.changed!(*args) end end end end |