Skip to content

Commit

Permalink
issue #548: use empty_dirname? method
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Jan 13, 2022
1 parent 670a92d commit 098aec6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/listen/record.rb
Expand Up @@ -18,7 +18,7 @@ def initialize(directory, silencer)
end

def add_dir(rel_path)
if ![nil, '', '.'].include?(rel_path)
if !empty_dirname?(rel_path.to_s)
@tree[rel_path] ||= {}
end
end
Expand All @@ -35,7 +35,7 @@ def unset_path(rel_path)

def file_data(rel_path)
dirname, basename = Pathname(rel_path).split.map(&:to_s)
if [nil, '', '.'].include?(dirname)
if empty_dirname?(dirname)
@tree[basename] ||= {}
@tree[basename].dup
else
Expand All @@ -47,7 +47,7 @@ def file_data(rel_path)

def dir_entries(rel_path)
rel_path_s = rel_path.to_s
subtree = if ['', '.'].include?(rel_path_s)
subtree = if empty_dirname?(rel_path_s)
@tree
else
@tree[rel_path_s]
Expand All @@ -74,12 +74,16 @@ def build

private

def empty_dirname?(dirname)
dirname == '.' || dirname == ''
end

def reset_tree
@tree = Hash.new { |h, k| h[k] = {} }
end

def _fast_update_file(dirname, basename, data)
if [nil, '', '.'].include?(dirname)
if empty_dirname?(dirname.to_s)
@tree[basename] = (@tree[basename] || {}).merge(data)
else
@tree[dirname] ||= {}
Expand All @@ -90,7 +94,7 @@ def _fast_update_file(dirname, basename, data)
def _fast_unset_path(dirname, basename)
# this may need to be reworked to properly remove
# entries from a tree, without adding non-existing dirs to the record
if [nil, '', '.'].include?(dirname)
if empty_dirname?(dirname.to_s)
if @tree.key?(basename)
@tree.delete(basename)
end
Expand Down

0 comments on commit 098aec6

Please sign in to comment.