Skip to content

Commit

Permalink
issue guard#548: remove _auto_hash in favor of a reset_tree method
Browse files Browse the repository at this point in the history
  • Loading branch information
ColinDKelley committed Jan 9, 2022
1 parent 6f0f0ec commit af73ed4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/listen/record.rb
Expand Up @@ -12,7 +12,7 @@ class Record
attr_reader :root

def initialize(directory, silencer)
@tree = _auto_hash
reset_tree
@root = directory.to_s
@silencer = silencer
end
Expand Down Expand Up @@ -50,19 +50,19 @@ def dir_entries(rel_path)
subtree = if ['', '.'].include?(rel_path_s)
@tree
else
@tree[rel_path_s] ||= _auto_hash
@tree[rel_path_s]
end

subtree.each_with_object({}) do |(key, values), result|
# only return data for file entries
if values.respond_to?(:has_key?)
# only return data for file entries inside the dir (which will each be sub-hashes)
if values.is_a?(Hash)
result[key] = values.has_key?(:mtime) ? values : {}
end
end
end

def build
@tree = _auto_hash
reset_tree
# TODO: test with a file name given
# TODO: test other permissions
# TODO: test with mixed encoding
Expand All @@ -74,8 +74,8 @@ def build

private

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

def _fast_update_file(dirname, basename, data)
Expand Down

0 comments on commit af73ed4

Please sign in to comment.