Class: Listen::Directory
- Defined in:
- lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/directory.rb
Overview
TODO: refactor (turn it into a normal object, cache the stat, etc)
Class Method Summary collapse
- ._async_changes(snapshot, path, previous, options) ⇒ Object
- ._change(snapshot, type, path, options) ⇒ Object
- ._children(path) ⇒ Object
-
.ascendant_of?(base, other) ⇒ Boolean
rubocop:enable Metrics/MethodLength.
-
.scan(snapshot, rel_path, options) ⇒ Object
rubocop:disable Metrics/MethodLength.
Class Method Details
._async_changes(snapshot, path, previous, options) ⇒ Object
62 63 64 65 66 67 68 69 70 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/directory.rb', line 62 def self._async_changes(snapshot, path, previous, ) fail "Not a Pathname: #{path.inspect}" unless path.respond_to?(:children) previous.each do |entry, data| # TODO: this is a hack with insufficient testing type = data.key?(:mtime) ? :file : :dir rel_path_s = (path + entry).to_s _change(snapshot, type, rel_path_s, ) end end |
._change(snapshot, type, path, options) ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/directory.rb', line 72 def self._change(snapshot, type, path, ) return snapshot.invalidate(type, path, ) if type == :dir # Minor param cleanup for tests # TODO: use a dedicated Event class opts = .dup opts.delete(:recursive) snapshot.invalidate(type, path, opts) end |
._children(path) ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/directory.rb', line 82 def self._children(path) return path.children unless RUBY_ENGINE == 'jruby' # JRuby inconsistency workaround, see: # https://github.com/jruby/jruby/issues/3840 exists = path.exist? directory = path.directory? exists && !directory and raise Errno::ENOTDIR, path.to_s path.children end |
.ascendant_of?(base, other) ⇒ Boolean
rubocop:enable Metrics/MethodLength
56 57 58 59 60 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/directory.rb', line 56 def self.ascendant_of?(base, other) other.ascend do |ascendant| break true if base == ascendant end end |
.scan(snapshot, rel_path, options) ⇒ Object
rubocop:disable Metrics/MethodLength
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 48 49 50 51 52 53 |
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/listen-3.8.0/lib/listen/directory.rb', line 9 def self.scan(snapshot, rel_path, ) record = snapshot.record dir = Pathname.new(record.root) previous = record.dir_entries(rel_path) record.add_dir(rel_path) # TODO: use children(with_directory: false) path = dir + rel_path current = Set.new(_children(path)) Listen.logger.debug do format('%s: %s(%s): %s -> %s', ([:silence] ? 'Recording' : 'Scanning'), rel_path, .inspect, previous.inspect, current.inspect) end begin current.each do |full_path| type = ::File.lstat(full_path.to_s).directory? ? :dir : :file item_rel_path = full_path.relative_path_from(dir).to_s _change(snapshot, type, item_rel_path, ) end rescue Errno::ENOENT # The directory changed meanwhile, so rescan it current = Set.new(_children(path)) retry end # TODO: this is not tested properly previous = previous.reject { |entry, _| current.include?(path + entry) } _async_changes(snapshot, Pathname.new(rel_path), previous, ) rescue Errno::ENOENT, Errno::EHOSTDOWN record.unset_path(rel_path) _async_changes(snapshot, Pathname.new(rel_path), previous, ) rescue Errno::ENOTDIR # TODO: path not tested record.unset_path(rel_path) _async_changes(snapshot, path, previous, ) _change(snapshot, :file, rel_path, ) rescue Listen.logger.warn { format('scan DIED: %s:%s', $ERROR_INFO, $ERROR_POSITION * "\n") } raise end |