philiprehberger-file_watcher 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 72955a87c0c7532aaae1770f832fa481ebdb5e8e7486a6256cd3efe22b96980a
4
- data.tar.gz: 30fe17eb9808992fdbb081af22539beeef4ee3b8eeeda33db86222a95fc77d3d
3
+ metadata.gz: a915f31902d0bdde628463388067c0705492168b86f4b837cef701a5cce4a3cc
4
+ data.tar.gz: f55c07836c8c9057066e1d178c12c4e2a0230758778517accf156f6dcb36e446
5
5
  SHA512:
6
- metadata.gz: 932825e2603306e53383ce80b69c1aeac3690bc3e5de594b71cf65b065c6cb33adc685dc63d39e7aa829f3616bb118fa81d674e2271cc0039446826fa73f7cf1
7
- data.tar.gz: e271b72444e9221cc59954c4f2d9c4c1a601b79ce90386848638f018d3a6c4aecf9a11108acf97df96c39caefb535d5a9556e492ef7540b0bc2e4b89bba5276a
6
+ metadata.gz: 1a46bd5ae6d94a4040b8cedd836466f5543bc67ca739ad6af17b6af09ca381ede30f1dcb4730bf0b2fae3e68dae567b7ac7cd903a703ec0985ed0bc00e206e15
7
+ data.tar.gz: a558ec156f7e6f0b7a30812b60b603499f4b022b92e401715e8eea849ed2cf716b5fa197f3ec6faca534f5ea5dff3b777aead24d382e46d7a9ab2a7151c1e40b
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-04-26
11
+
12
+ ### Added
13
+
14
+ - `Watcher#stats` returning a hash with `:tracked_files`, `:total_changes`, and `:last_change_at`
15
+
10
16
  ## [0.3.0] - 2026-04-10
11
17
 
12
18
  ### Added
data/README.md CHANGED
@@ -133,6 +133,18 @@ snapshot.each do |path, info|
133
133
  end
134
134
  ```
135
135
 
136
+ ### Stats
137
+
138
+ ```ruby
139
+ require "philiprehberger/file_watcher"
140
+
141
+ watcher = Philiprehberger::FileWatcher::Watcher.new("./src")
142
+ watcher.start
143
+
144
+ stats = watcher.stats
145
+ # => { tracked_files: 42, total_changes: 7, last_change_at: 2026-04-26 12:00:00 +0000 }
146
+ ```
147
+
136
148
  ## API
137
149
 
138
150
  ### `FileWatcher.watch(paths, interval:, glob:, exclude:, debounce:, &block)`
@@ -161,6 +173,7 @@ Blocking method. Stops on `Interrupt` (Ctrl+C).
161
173
  | `#resume` | Resume change detection with a fresh snapshot |
162
174
  | `#paused?` | Returns `true` if the watcher is currently paused |
163
175
  | `#snapshot` | Returns a hash of `{path => {mtime:, size:}}` for all tracked files |
176
+ | `#stats` | Returns a hash with `:tracked_files`, `:total_changes`, and `:last_change_at` |
164
177
 
165
178
  ### `FileWatcher::Change`
166
179
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module FileWatcher
5
- VERSION = '0.3.0'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -27,6 +27,8 @@ module Philiprehberger
27
27
  @paused = false
28
28
  @snapshot = {}
29
29
  @pending_debounce = {}
30
+ @total_changes = 0
31
+ @last_change_at = nil
30
32
  end
31
33
 
32
34
  # Register a callback for a specific change type.
@@ -122,6 +124,22 @@ module Philiprehberger
122
124
  end
123
125
  end
124
126
 
127
+ # Return runtime statistics for the watcher.
128
+ #
129
+ # The returned hash is a fresh copy on each call and safe to mutate.
130
+ #
131
+ # @return [Hash] with keys :tracked_files (Integer), :total_changes (Integer),
132
+ # and :last_change_at (Time or nil)
133
+ def stats
134
+ @mutex.synchronize do
135
+ {
136
+ tracked_files: @snapshot.size,
137
+ total_changes: @total_changes,
138
+ last_change_at: @last_change_at
139
+ }
140
+ end
141
+ end
142
+
125
143
  private
126
144
 
127
145
  def poll_loop
@@ -148,6 +166,10 @@ module Philiprehberger
148
166
  @mutex.synchronize do
149
167
  changes = diff_snapshots(@snapshot, current)
150
168
  @snapshot = current
169
+ unless changes.empty?
170
+ @total_changes += changes.size
171
+ @last_change_at = Time.now
172
+ end
151
173
  changes
152
174
  end
153
175
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-file_watcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-10 00:00:00.000000000 Z
11
+ date: 2026-04-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Watch files and directories for changes using polling. Detects created,
14
14
  modified, and deleted files with configurable intervals and glob patterns.