Skip to content

Commit

Permalink
WIP: Richer calls to _queue_change
Browse files Browse the repository at this point in the history
  • Loading branch information
floehopper committed Aug 7, 2019
1 parent 87ac6ea commit 27c157a
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions lib/listen/adapter/jruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ def _configure(directory, &_callback)
java_import 'java.nio.file.Paths'
java_import 'java.nio.file.StandardWatchEventKinds'

event_kinds = [
StandardWatchEventKinds::ENTRY_CREATE,
StandardWatchEventKinds::ENTRY_MODIFY,
StandardWatchEventKinds::ENTRY_DELETE
]
@event_kind_map ||= {
StandardWatchEventKinds::ENTRY_CREATE => :added,
StandardWatchEventKinds::ENTRY_MODIFY => :modified,
StandardWatchEventKinds::ENTRY_DELETE => :removed
}

@watcher ||= FileSystems.getDefault.newWatchService
p @watcher.class.name
@keys ||= {}
path = Paths.get(directory.to_s)
key = path.register(@watcher, *event_kinds)
key = path.register(@watcher, *@event_kind_map.keys)
@keys[key] = path
end

Expand All @@ -38,9 +38,17 @@ def _run
next if kind == StandardWatchEventKinds::OVERFLOW
name = event.context
child = dir.resolve(name)
p child.to_s
pathname = Pathname.new(child.to_s).dirname
_queue_change(:dir, pathname, '.', recursive: true)
dirname = Pathname.new(child.to_s).dirname
full_path = Pathname.new(child.to_s)
if full_path.directory?
p [:dir, dirname]
_queue_change(:dir, dirname, '.', recursive: true)
elsif full_path.exist?
path = full_path.relative_path_from(dirname)
changed = @event_kind_map[kind]
p [:file, dirname, path.to_s, changed: changed]
_queue_change(:file, dirname, path.to_s, changed: changed)
end
end
end
valid = key.reset
Expand Down

0 comments on commit 27c157a

Please sign in to comment.