0.0
No commit activity in last 3 years
No release in over 3 years
A barebones file system watcher which uses native file system events for Linux, OSx, and Windows.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
>= 0

Runtime

~> 0.1
 Project Readme

![Feather Watch](/Feather Watch.png?raw=true)

Light weight, cross platform, file system watcher.

Gem Version Build Status Coverage Status Code Climate feather_watch API Documentation Flattr this git repo

Installation

Add this line to your application's Gemfile:

gem 'feather_watch'

And then execute:

$ bundle

Or install it yourself as:

$ gem install feather_watch

Usage

require "feather_watch"
callback = lambda{|e| puts "Event #{e[:status]} on file #{e[:file]}"}
paths_to_watch = "/" #can be a string or array of string, eg: ["/home/data", "/home/pictures"]
watcher = FeatherWatch.new(paths_to_watch, callback)
watcher.start #non-blocking

#To stop:
watcher.stop

Received statuses

  • :added
  • :modified
  • :removed

Important Notes!

Events on OSx, also known as darwin, is current an approximation as the underlying libraries does not currently support actual events. Thus on OSx, you get :removed if the file received does not exist by checking File.file?(the_file). If it does exist you get :modified. So you will not get any :added events on OSx.

Feather Watch will receive very many file events, even for temp files. Care should be taken when handling the events. Make sure to only process what you need. For instance, you should check against temp-files, and skip those events. Example:

#black list approach
un_accepted_file_types = ["tmp", "cache", "db"]
callback = lambda{|e| use_event(e) unless un_accepted_file_types.include?(e[:file].split(".")[-1])} 

#white list approach
accepted_file_types = ["png", "jpg", "jpeg", "gif"]
callback = lambda{|e| use_event(e) if accepted_file_types.include?(e[:file].split(".")[-1])}

You need to take care to filter out what you do not need for each target platform.

Quirks:

All tests succeed individually on Windows, however, if they are run at the same time usring the command rspec some of the tests fail. This is due to file locking which is currently unresolved.

License:

MIT

Contributing

  1. Fork it ( https://github.com/stephan-nordnes-eriksen/feather_watch/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