Giter VIP home page Giter VIP logo

ruby-fsevent's Introduction

ruby-fsevent

A native extension exposing the OS X FSEvent API.

Register the directories you want to watch, create a custom callback, and your callback will fire everytime a change occurs in the registered directories.

Example

class PrintChange < FSEvent
  def on_change(directories)
    puts "Detected change in: #{directories.inspect}"
  end
end

printer = PrintChange.new
printer.watch_directories %W(#{Dir.pwd} /tmp)
printer.start

Examine ruby-fsevent/examples

  1. rake make
  2. ruby examples/print_changes.rb
  3. Notice that the examples directory and the /tmp directory are being monitored
  4. Make a change to either directory and watch the callback fire

TODO

  • Documentation
  • Add ability to register a block as a callback handler, on_change would then call the block. This removes the need for subclassing.
  • Expose an optional ruby library to show file changes, not just directory changes
  • Do more in Ruby, less in C

Reasoning

I'm tired of recompiling RubyCocoa just get Rspactor working whenever I switch Ruby versions. Hopefully, this gem will break that dependency.

Watchr and Kicker have recently grabbed my attention. They allow you to watch directories for changes and create custom event handlers. Unfortunately, Watchr has a 4-5 second delay when using it with Rev (recommended) before your callback is fires. Without Rev, Watchr degrades to a 0.5 second Ruby loop which we all know is not resource-friendly. Now, Watchr could easily add native FSEvents as a new backend for Mac users.

Kicker already uses the FSEvents API but it requires RubyCocoa just like Rspactor. They could easily switch their dependency to this native extension and remove the need for RubyCocoa.

With a generic, native interface to the FSEvent API we, as Rubyists can harness the power of OSX FSEvents without depending on RubyCocoa.

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.

Copyright

Copyright (c) 2009 Sandro Turriate. See MIT_LICENSE for details.

ruby-fsevent's People

Contributors

kch avatar sandro avatar troyk avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.