Class: SimpleCov::CLI::Watch::Poller
- Inherits:
-
Object
- Object
- SimpleCov::CLI::Watch::Poller
- Defined in:
- lib/simplecov/cli/watch/poller.rb
Overview
Watches a fixed set of paths by polling mtimes, the trade chosen over a filesystem-event dependency for a command that is optional to begin with. Editors that save through a temporary file plus rename still move the final path's mtime, which is all this looks at.
Instance Method Summary collapse
- #changes ⇒ Object
-
#initialize ⇒ Poller
constructor
A new instance of Poller.
- #size ⇒ Object
- #stamp(path) ⇒ Object
-
#watch(paths) ⇒ Object
Replaces the watched set, snapshotting current mtimes.
Constructor Details
#initialize ⇒ Poller
Returns a new instance of Poller.
11 12 13 |
# File 'lib/simplecov/cli/watch/poller.rb', line 11 def initialize @snapshot = {} #: Hash[String, untyped] end |
Instance Method Details
#changes ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/simplecov/cli/watch/poller.rb', line 25 def changes changed = [] #: Array[String] @snapshot.each_key do |path| now = stamp(path) next if now.eql?(@snapshot.fetch(path)) @snapshot[path] = now changed << path end changed end |
#size ⇒ Object
21 22 23 |
# File 'lib/simplecov/cli/watch/poller.rb', line 21 def size @snapshot.size end |
#stamp(path) ⇒ Object
37 38 39 40 41 |
# File 'lib/simplecov/cli/watch/poller.rb', line 37 def stamp(path) File.mtime(path) rescue SystemCallError nil end |
#watch(paths) ⇒ Object
Replaces the watched set, snapshotting current mtimes. A path with no file snapshots as nil, so appearing counts as a change.
17 18 19 |
# File 'lib/simplecov/cli/watch/poller.rb', line 17 def watch(paths) @snapshot = paths.to_h { |path| [path, stamp(path)] } end |