2009-12-16 16:57:16 +00:00
|
|
|
require File.join(File.dirname(__FILE__), 'rubycocoa/fsevents')
|
2009-09-03 05:42:59 +00:00
|
|
|
|
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
|
2009-12-16 16:57:16 +00:00
|
|
|
|
2009-08-30 18:37:24 +00:00
|
|
|
def add_path(path, preload=true)
|
2009-09-06 05:59:30 +00:00
|
|
|
handler = FSSM::State.new(path)
|
2009-09-03 05:42:59 +00:00
|
|
|
@handlers["#{path}"] = handler
|
2009-12-16 16:57:16 +00:00
|
|
|
|
2009-09-06 05:59:30 +00:00
|
|
|
fsevent = Rucola::FSEvents.new("#{path}", {:latency => 0.5}) do |events|
|
2009-09-03 05:42:59 +00:00
|
|
|
events.each do |event|
|
|
|
|
handler.refresh(event.path)
|
|
|
|
end
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
2009-12-16 16:57:16 +00:00
|
|
|
|
2009-09-03 05:42:59 +00:00
|
|
|
fsevent.create_stream
|
2009-09-06 05:59:30 +00:00
|
|
|
handler.refresh(path.to_pathname, true) if preload
|
2009-09-03 05:42:59 +00:00
|
|
|
fsevent.start
|
|
|
|
@fsevents << fsevent
|
2009-08-30 18:37:24 +00:00
|
|
|
end
|
2009-12-16 16:57:16 +00:00
|
|
|
|
2009-08-30 18:37:24 +00:00
|
|
|
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
|