Class: Listen::Directory
- Inherits:
-
Object
- Object
- Listen::Directory
- Defined in:
- lib/listen/directory.rb
Class Method Summary collapse
- ._async_changes(dir, path, queue, previous, options) ⇒ Object
- ._change(queue, type, dir, path, options) ⇒ Object
- ._log(type, &block) ⇒ Object
- .scan(queue, sync_record, dir, rel_path, options) ⇒ Object
Class Method Details
._async_changes(dir, path, queue, previous, options) ⇒ Object
49 50 51 52 53 54 55 |
# File 'lib/listen/directory.rb', line 49 def self._async_changes(dir, path, queue, previous, ) previous.each do |entry, data| # TODO: this is a hack with insufficient testing type = data.key?(:mtime) ? :file : :dir _change(queue, type, dir, (Pathname(path) + entry).to_s, ) end end |
._change(queue, type, dir, path, options) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/listen/directory.rb', line 57 def self._change(queue, type, dir, path, ) return queue.change(type, dir, path, ) if type == :dir # Minor param cleanup for tests # TODO: use a dedicated Event class opts = .dup opts.delete(:recursive) if opts.empty? queue.change(type, dir, path) else queue.change(type, dir, path, opts) end end |
._log(type, &block) ⇒ Object
71 72 73 74 75 76 |
# File 'lib/listen/directory.rb', line 71 def self._log(type, &block) return unless Celluloid.logger Celluloid.logger.send(type) do block.call end end |
.scan(queue, sync_record, dir, rel_path, options) ⇒ Object
5 6 7 8 9 10 11 12 13 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 47 |
# File 'lib/listen/directory.rb', line 5 def self.scan(queue, sync_record, dir, rel_path, ) return unless (record = sync_record.async) previous = sync_record.dir_entries(dir, rel_path) record.add_dir(dir, rel_path) # TODO: use children(with_directory: false) path = dir + rel_path current = Set.new(path.children) _log(:debug) do format('%s: %s(%s): %s -> %s', ([:silence] ? 'Recording' : 'Scanning'), rel_path, .inspect, previous.inspect, current.inspect) end current.each do |full_path| type = full_path.directory? ? :dir : :file item_rel_path = full_path.relative_path_from(dir).to_s _change(queue, type, dir, item_rel_path, ) end # TODO: this is not tested properly previous = previous.reject { |entry, _| current.include? path + entry } _async_changes(dir, rel_path, queue, previous, ) rescue Errno::ENOENT, Errno::EHOSTDOWN record.unset_path(dir, rel_path) _async_changes(dir, rel_path, queue, previous, ) rescue Errno::ENOTDIR # TODO: path not tested record.unset_path(dir, rel_path) _async_changes(dir, path, queue, previous, ) _change(queue, :file, dir, rel_path, ) rescue _log(:warn) do format('scan DIED: %s:%s', $ERROR_INFO, $ERROR_POSITION * "\n") end raise end |