<commit_before>module FSSM::State
  class Directory
    attr_reader :path

    def initialize(path, options={})
      @path = path
      @options = options
      @cache = FSSM::Tree::Cache.new
    end

    def refresh(base=nil, skip_callbacks=false)
      previous, current = recache(base || @path.to_pathname)

      unless skip_callbacks
        deleted(previous, current)
        created(previous, current)
        modified(previous, current)
      end
    end

    private

    def created(previous, current)
      (current.keys - previous.keys).sort.each do |file|
        @path.create(file, current[file][1])
      end
    end

    def deleted(previous, current)
      (previous.keys - current.keys).
        sort {|a, b| b <=> a}.
        each {|file| @path.delete(file, previous[file][1])}
    end

    def modified(previous, current)
      (current.keys & previous.keys).each do |file|<commit_msg>Sort.reverse is clearer than sort with a block<commit_after>module FSSM::State
  class Directory
    attr_reader :path

    def initialize(path, options={})
      @path = path
      @options = options
      @cache = FSSM::Tree::Cache.new
    end

    def refresh(base=nil, skip_callbacks=false)
      previous, current = recache(base || @path.to_pathname)

      unless skip_callbacks
        deleted(previous, current)
        created(previous, current)
        modified(previous, current)
      end
    end

    private

    def created(previous, current)
      (current.keys - previous.keys).sort.each do |file|
        @path.create(file, current[file][1])
      end
    end

    def deleted(previous, current)
      (previous.keys - current.keys).
        sort.
        reverse.
        each {|file| @path.delete(file, previous[file][1])}
    end

    def modified(previous, current)
      (current.keys & previous.keys).each do |file|
{'fraction_non_alphanumeric': 0.11382113821138211, 'fraction_numerical': 0.002168021680216802, 'mean_word_length': 2.55, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4483016', 'n_tokens_mistral': 561, 'n_tokens_neox': 544, 'n_words': 137}