2009-09-03 05:42:59 +00:00
|
|
|
require 'fssm/fsevents'
|
|
|
|
|
2009-08-30 18:37:24 +00:00
|
|
|
module FSSM::Backends
|
2009-09-03 05:42:59 +00:00
|
|
|
class FSEvents
|
|
|
|
def initialize
|
|
|
|
@handlers = {}
|
|
|
|
@fsevents = []
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def add_path(path, preload=true)
|
2009-09-03 05:42:59 +00:00
|
|
|
handler = FSSM::State.new(path, preload)
|
|
|
|
@handlers["#{path}"] = handler
|
2009-08-30 18:37:24 +00:00
|
|
|
|
2009-09-03 05:42:59 +00:00
|
|
|
fsevent = Rucola::FSEvents.new("#{path}") do |events|
|
|
|
|
events.each do |event|
|
|
|
|
handler.refresh(event.path)
|
|
|
|
end
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
|
|
|
|
2009-09-03 05:42:59 +00:00
|
|
|
fsevent.create_stream
|
|
|
|
fsevent.start
|
|
|
|
@fsevents << fsevent
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
begin
|
|
|
|
OSX.CFRunLoopRun
|
|
|
|
rescue Interrupt
|
2009-09-03 05:42:59 +00:00
|
|
|
@fsevents.each do |fsev|
|
|
|
|
fsev.stop
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2009-09-03 05:42:59 +00:00
|
|
|
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
|
|
|
end
|