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

  1. Add the dependency to your shard.yml:

    dependencies:
      watcher:
        github: rubyattack3r/watcher
  2. 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

  1. Fork it (https://github.com/rubyattack3r/watcher/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors