<commit_before>module LivereloadRails
  class Watcher
    def initialize(paths, matchers:, &update)
      LivereloadRails.logger.debug "Watching #{paths} for changes."
      @watcher = FileWatcher.new(paths)
      @matchers = matchers
      @update = update
    end

    def run(timeout = 0.2)
      @watcher.watch(timeout) do |path, event|
        if filename = translate(path)
          if filename.empty?
            LivereloadRails.logger.debug "#{path} -> ignored."
          else
            LivereloadRails.logger.debug "#{path} -> #{filename}."
            @update[filename]
          end
        else
          LivereloadRails.logger.debug "#{path} -> no match."
        end
      end
    end

    def translate(path)
      @matchers.each do |name, matcher|
        if value = matcher.call(path)
          return value
        end
      end
    end
  end
end<commit_msg>Only reload on file changes (not directories).<commit_after>module LivereloadRails
  class Watcher
    def initialize(paths, matchers:, &update)
      LivereloadRails.logger.debug "Watching #{paths} for changes."
      @watcher = FileWatcher.new(paths)
      @matchers = matchers
      @update = update
    end

    def run(timeout = 0.2)
      @watcher.watch(timeout) do |path, event|
        unless FileTest.file?(path)
          LivereloadRails.logger.debug "#{path} -> not a file."
          next
        end

        unless filename = translate(path)
          LivereloadRails.logger.debug "#{path} -> no match."
          next
        end

        if filename.empty?
          LivereloadRails.logger.debug "#{path} -> ignored."
          next
        end

        LivereloadRails.logger.debug "#{path} -> #{filename}."
        @update[filename]
      end
    end

    def translate(path)
      @matchers.each do |name, matcher|
        if value = matcher.call(path)
          return value
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.10193413486670151, 'fraction_numerical': 0.0020909566126502874, 'mean_word_length': 1.9628482972136223, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '339832', 'n_tokens_mistral': 576, 'n_tokens_neox': 554, 'n_words': 144}