Skip to content

Ragmaanir/watcher

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 Watcher.watch to watch files or file groups, for example:

require "watcher"

Watcher.watch("src/assets/js/*.js") do |changes, state|
  # changes is a Hash(String, Watcher::Status) mapping a filename to its change-status
  # change-status is Created | Modified | Deleted
  changes.each do |name, status|
    puts "{status}: #{name}"
  end
end

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

spawn do
  Watcher.watch(["src/assets/*.css", "src/views/*.html"]) do |changes|
    # ...
  end
end

# Other watcher
Watcher.watch(...) do |changes|
 # ...
end

And you can change time interval for a watcher.

Watcher.watch("public/*.json", interval: 0.5) do |changes|
  # ...
end

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

About

Crystal shard to watch file changes using File.stat

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Crystal 100.0%