class Providence::EventHandler::Darwin
Uses ruby-fsevents (github.com/thibaudgg/rb-fsevent)
Attributes
watched_paths[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/providence/event_handlers/darwin.rb, line 11 def initialize super end
Public Instance Methods
listen(monitored_paths)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 15 def listen(monitored_paths) watch_paths(monitored_paths) run end
refresh(monitored_paths)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 20 def refresh(monitored_paths) stop listen(monitored_paths) end
Private Instance Methods
dirs_in(paths)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 34 def dirs_in(paths) paths.map {|path| path.dirname.to_s }.uniq end
event_type(path)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 54 def event_type(path) return :deleted if !path.exist? return :modified if path.mtime > @reference_times[path][:mtime] return :accessed if path.atime > @reference_times[path][:atime] return :changed if path.ctime > @reference_times[path][:ctime] nil end
monitored_paths_for(dir)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 49 def monitored_paths_for(dir) dir = Pathname(dir).expand_path @watched_paths.select {|path| path.dirname.expand_path == dir } end
process_changes(dirs)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 38 def process_changes(dirs) dirs.each do |dir| paths = monitored_paths_for(dir) type = nil path = paths.find {|path| type = event_type(path) } notify(path, type) unless path.nil? end update_reference_times end
update_reference_times()
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 62 def update_reference_times @reference_times = {} now = Time.now @watched_paths.each do |path| @reference_times[path] = {} @reference_times[path][:atime] = now @reference_times[path][:mtime] = now @reference_times[path][:ctime] = now end end
watch_paths(paths)
click to toggle source
# File lib/providence/event_handlers/darwin.rb, line 26 def watch_paths(paths) @watched_paths = paths watch(dirs_in(paths)) do |dirs| process_changes(dirs) end update_reference_times end