Module: EMDirWatcher
- Defined in:
- lib/em-dir-watcher.rb,
lib/em-dir-watcher/tree.rb,
lib/em-dir-watcher/monitor.rb,
lib/em-dir-watcher/platform/mac.rb,
lib/em-dir-watcher/platform/linux.rb,
lib/em-dir-watcher/platform/windows.rb,
lib/em-dir-watcher/invokers/subprocess_invoker.rb,
lib/em-dir-watcher/platform/mac/rubycocoa_watcher.rb,
lib/em-dir-watcher/platform/mac/ffi_fsevents_watcher.rb,
lib/em-dir-watcher/platform/windows/path_to_ruby_exe.rb
Defined Under Namespace
Modules: Invokers, Platform Classes: Entry, NameGlobMatcher, PathGlobMatcher, RegexpMatcher, Tree
Constant Summary collapse
- PLATFORM =
ENV['EM_DIR_WATCHER_PLATFORM'] || case Config::CONFIG['target_os'] when /mswin|mingw/ then 'Windows' when /darwin/ then 'Mac' when /linux/ then 'Linux' else 'NIX' end
- Watcher =
Platform.const_get(PLATFORM)::Watcher
- DEFAULT_OPTIONS =
{ :exclude => [], :include_only => nil, :grace_period => 0.0, }.freeze
- INFINITELY_SMALL_PERIOD =
0.001
Class Method Summary collapse
Class Method Details
.watch(path, options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/em-dir-watcher/monitor.rb', line 14 def self.watch path, ={} unless (invalid_keys = .keys - DEFAULT_OPTIONS.keys).empty? raise StandardError, "Unsupported options given to EMDirWatcher.watch: " + invalid_keys.join(", ") end = DEFAULT_OPTIONS.merge() grace_period = [:grace_period] tree = Tree.new path, [:include_only], [:exclude] pending_refresh_requests = Set.new process_pending_refresh_requests_scheduled = false process_pending_refresh_requests = lambda do process_pending_refresh_requests_scheduled = false changed_paths = Set.new pending_refresh_requests.each do |change_scope, refresh_subtree| changed_paths += tree.refresh! change_scope, refresh_subtree end yield changed_paths.to_a unless changed_paths.empty? end Watcher.new path, [:include_only], [:exclude] do |change_scope, refresh_subtree| pending_refresh_requests << [change_scope, refresh_subtree] if grace_period <= INFINITELY_SMALL_PERIOD process_pending_refresh_requests.call else unless process_pending_refresh_requests_scheduled EM.add_timer grace_period, &process_pending_refresh_requests process_pending_refresh_requests_scheduled = true end end end end |