Class: Listen::Adapter::BSD
- Inherits:
-
Base
- Object
- Base
- Listen::Adapter::BSD
show all
- Defined in:
- lib/listen/adapter/bsd.rb
Constant Summary
collapse
- OS_REGEXP =
/bsd|dragonfly/i
- DEFAULTS =
{
events: [
:delete,
:write,
:extend,
:attrib,
:rename
]
}.freeze
- BUNDLER_DECLARE_GEM =
<<-EOS.gsub(/^ {6}/, '')
Please add the following to your Gemfile to avoid polling for changes:
gem 'rb-kqueue', '>= 0.2'
EOS
Instance Attribute Summary
Attributes inherited from Base
#config, #options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#_log_exception, #_queue_change, #_stop, #_timed, #configure, #initialize, #start, #started?, #stop
Class Method Details
.usable? ⇒ Boolean
28
29
30
31
32
33
34
35
36
|
# File 'lib/listen/adapter/bsd.rb', line 28
def self.usable?
return false unless super
require 'rb-kqueue'
require 'find'
true
rescue LoadError
Listen.adapter_warn(BUNDLER_DECLARE_GEM)
false
end
|
Instance Method Details
#_change(event_flags) ⇒ Object
70
71
72
73
74
75
76
77
|
# File 'lib/listen/adapter/bsd.rb', line 70
def _change(event_flags)
{ modified: [:attrib, :extend],
added: [:write],
removed: [:rename, :delete] }.each do |change, flags|
return change unless (flags & event_flags).empty?
end
nil
end
|
40
41
42
43
44
45
46
|
# File 'lib/listen/adapter/bsd.rb', line 40
def _configure(directory, &callback)
@worker ||= KQueue::Queue.new
@callback = callback
_find(directory.to_s) { |path| _watch_file(path, @worker) }
end
|
#_event_path(event) ⇒ Object
79
80
81
|
# File 'lib/listen/adapter/bsd.rb', line 79
def _event_path(event)
Pathname.new(event.watcher.path)
end
|
#_find(*paths, &block) ⇒ Object
99
100
101
|
# File 'lib/listen/adapter/bsd.rb', line 99
def _find(*paths, &block)
Find.send(:find, *paths, &block)
end
|
#_process_event(dir, event) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
# File 'lib/listen/adapter/bsd.rb', line 52
def _process_event(dir, event)
full_path = _event_path(event)
if full_path.directory?
_queue_change(:dir, dir, '.', recursive: true)
elsif full_path.exist?
path = full_path.relative_path_from(dir)
_queue_change(:file, dir, path.to_s, change: _change(event.flags))
end
_watch_for_new_file(event) if full_path.directory?
end
|
#_run ⇒ Object
48
49
50
|
# File 'lib/listen/adapter/bsd.rb', line 48
def _run
@worker.run
end
|
#_watch_file(path, queue) ⇒ Object
92
93
94
95
96
|
# File 'lib/listen/adapter/bsd.rb', line 92
def _watch_file(path, queue)
queue.watch_file(path, *options.events, &@callback)
rescue Errno::ENOENT => e
Listen.logger.warn "kqueue: watch file failed: #{e.message}"
end
|
#_watch_for_new_file(event) ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/listen/adapter/bsd.rb', line 83
def _watch_for_new_file(event)
queue = event.watcher.queue
_find(_event_path(event).to_s) do |file_path|
unless queue.watchers.find { |_, v| v.path == file_path.to_s }
_watch_file(file_path, queue)
end
end
end
|