Watcher
A lightweight, efficient file system watcher for Crystal that monitors directories for file changes. It uses non-blocking operations to track when files are added, modified, or removed from watched directories.
Installation
-
Add the dependency to your
shard.yml
:dependencies: watcher: github: rubyattack3r/watcher
-
Run
shards install
Usage
require "watcher"
# Create a watcher that checks every 500ms
watcher = Watcher.new(500.milliseconds)
# Add directories to monitor
watcher.add("path/to/watch")
# Handle file changes
watcher.on_event do |event|
case event
when Watcher::AddedEvent
puts "Added: #{event.path}"
when Watcher::ModifiedEvent
puts "Modified: #{event.path}"
when Watcher::RemovedEvent
puts "Removed: #{event.path}"
end
end
# Start monitoring
watcher.start
# Later, when done...
watcher.stop
Contributing
- Fork it (https://github.com/rubyattack3r/watcher/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- rubyattack3r - creator and maintainer