Class Rucola::FSEvents
In: lib/vendor/fssm/fsevents.rb
Parent: Object

Methods

create_stream   new   start   start_watching   stop  

Classes and Modules

Class Rucola::FSEvents::FSEvent
Class Rucola::FSEvents::StreamError

Attributes

allocator  [RW] 
context  [RW] 
flags  [RW] 
latency  [RW] 
paths  [R] 
since  [RW] 
stream  [R] 

Public Class methods

Creates a new FSEvents `watchdog` object. You can specify a list of paths to watch and options to control the behaviour of the watchdog. The block you pass serves as a callback when an event is generated on one of the specified paths.

  fsevents = FSEvents.new('/etc/passwd') { Mailer.send_mail("Someone touched the password file!") }
  fsevents.create_stream
  fsevents.start

  fsevents = FSEvents.new('/home/upload', :since => UploadWatcher.last_event_id) do |events|
    events.each do |event|
      UploadWatcher.last_event_id = event.id
      event.files.each do |file|
        UploadWatcher.logfile.append("#{file} was changed")
      end
    end
  end

*:since: The service will report events that have happened after the supplied event ID. Never use 0 because that

  will cause every fsevent since the "beginning of time" to be reported. Use OSX::KFSEventStreamEventIdSinceNow
  if you want to receive events that have happened after this call. (Default: OSX::KFSEventStreamEventIdSinceNow).
  You can find the ID's passed with :since in the events passed to your block.

*:latency: Number of seconds to wait until an FSEvent is reported, this allows the service to bundle events. (Default: 0.0)

Please refer to the Cocoa documentation for the rest of the options.

Initializes a new FSEvents `watchdog` object and starts watching the directories you specify for events. The block is used as a handler for events, which are passed as the block‘s argument. This method is the easiest way to start watching some directories if you don‘t care about the details of setting up the event stream.

  Rucola::FSEvents.start_watching('/tmp') do |events|
    events.each { |event| log.debug("#{event.files.inspect} were changed.") }
  end

  Rucola::FSEvents.start_watching('/var/log/system.log', '/var/log/secure.log', :since => last_id, :latency => 5) do
    Growl.notify("Something was added to your log files!")
  end

Note that the method also returns the FSEvents object. This enables you to control the event stream if you want to.

  fsevents = Rucola::FSEvents.start_watching('/Volumes') do |events|
    events.each { |event| Growl.notify("Volume changes: #{event.files.to_sentence}") }
  end
  fsevents.stop

Public Instance methods

Create the stream. Raises a Rucola::FSEvents::StreamError if the stream could not be created.

Start the stream. Raises a Rucola::FSEvents::StreamError if the stream could not be started.

Stop the stream. You can resume it by calling `start` again.

[Validate]