Class: Steep::Daemon::Server::FileTracker
- Defined in:
- lib/steep/daemon/server.rb
Instance Method Summary collapse
- #flush_pending_changes ⇒ Object
-
#initialize ⇒ FileTracker
constructor
A new instance of FileTracker.
- #record_changes(changes) ⇒ Object
- #register(paths) ⇒ Object
- #track_and_detect(paths) ⇒ Object
Constructor Details
#initialize ⇒ FileTracker
Returns a new instance of FileTracker.
18 19 20 21 22 |
# File 'lib/steep/daemon/server.rb', line 18 def initialize @mtimes = {} @pending_changes = {} @mutex = Mutex.new end |
Instance Method Details
#flush_pending_changes ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/steep/daemon/server.rb', line 41 def flush_pending_changes @mutex.synchronize do changes = @pending_changes.to_a @pending_changes.clear changes.each do |path, type| @mtimes[path] = type == :deleted ? nil : safe_mtime(path) end changes end end |
#record_changes(changes) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/steep/daemon/server.rb', line 33 def record_changes(changes) @mutex.synchronize do changes.each do |path, type| @pending_changes[path] = type end end end |
#register(paths) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/steep/daemon/server.rb', line 24 def register(paths) @mutex.synchronize do paths.each do |path| key = path.to_s @mtimes[key] ||= safe_mtime(key) end end end |
#track_and_detect(paths) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/steep/daemon/server.rb', line 54 def track_and_detect(paths) @mutex.synchronize do changed = [] #: Array[[String, Symbol]] paths.each do |path| key = path.to_s current = safe_mtime(key) old = @mtimes[key] if old.nil? @mtimes[key] = current changed << [key, :created] if current elsif current != old @mtimes[key] = current type = current ? :changed : :deleted changed << [key, type] end end changed end end |