watcher

Watch file changes using File.stat monitor
0.1.7 released
faustinoaq/watcher
21 2 1
Faustino Aguilar

watcher

Build Status

Crystal shard to watch file changes. This shard use the same code implemented here (Guardian) and here (Sentry).

Installation

Add this to your application's shard.yml:

dependencies:
  watcher:
    github: faustinoaq/watcher

Usage

Use the keyword watch to watch files or file groups, for example:

require "watcher"

watch "src/assets/js/*.js", interval: 5.seconds do |event|
  event.on_change do |files|
    files.each do |file, timestamp|
      puts "File #{file} has changed at #{timestamp}"
    end
    # ...
  end
end

Aso you can have more than one watcher, just use spawn

spawn do
  watch ["src/assets/*.css", "src/views/*.html"] do |event|
    event.on_change do
      # ...
    end
  end
ens

Also you can change time interval for a watcher.

watch "public/big_project/*", interval: 5.seconds do |event|
  event.on_change do
    # ...
  end
end

Also you can use Watcher.watch instead of watch.

How does it work?

Watcher uses timestamps to check file changes every second, if you want some more advanced then you can use Watchbird that uses libnotify to check events like modify, access and delete but just work in Linux for now.

Contributing

  1. Fork it ( https://github.com/faustinoaq/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

  • faustinoaq Faustino Aguilar - creator, maintainer
watcher:
  github: faustinoaq/watcher
  version: ~> 0.1.7
License MIT
Crystal none

Authors

Dependencies 0

Development Dependencies 0

Last synced .
search fire star recently