<commit_before># frozen_string_literal: true

module Nanoc::Int
  # @api private
  class TempFilenameFactory
    # @return [String] The root directory for all temporary filenames
    attr_reader :root_dir

    # @return [Nanoc::Int::TempFilenameFactory] A common instance
    def self.instance
      @instance ||= new
    end

    def initialize
      @counts = {}
      @root_dir = Dir.mktmpdir('nanoc')
    end

    # @param [String] prefix A string prefix to include in the temporary
    #   filename, often the type of filename being provided.
    #
    # @return [String] A new unused filename
    def create(prefix)
      count = @counts.fetch(prefix, 0)
      @counts[prefix] = count + 1

      dirname  = File.join(@root_dir, prefix)
      filename = File.join(@root_dir, prefix, count.to_s)

      FileUtils.mkdir_p(dirname)

      filename
    end

    # @param [String] prefix A string prefix that indicates which temporary
    #   filenames should be deleted.
    #
    # @return [void]
    def cleanup(prefix)
      path = File.join(@root_dir, prefix)
      if File.exist?(path)
        FileUtils.rm_rf(path)
      end

      @counts.delete(prefix)

      if @counts.empty? && File.directory?(@root_dir)
        FileUtils.rm_rf(@root_dir)
      end
    end
  end
end<commit_msg>Fix indentation for temp_filename_factory.rb<commit_after># frozen_string_literal: true

module Nanoc
  module Int
    # @api private
    class TempFilenameFactory
      # @return [String] The root directory for all temporary filenames
      attr_reader :root_dir

      # @return [Nanoc::Int::TempFilenameFactory] A common instance
      def self.instance
        @instance ||= new
      end

      def initialize
        @counts = {}
        @root_dir = Dir.mktmpdir('nanoc')
      end

      # @param [String] prefix A string prefix to include in the temporary
      #   filename, often the type of filename being provided.
      #
      # @return [String] A new unused filename
      def create(prefix)
        count = @counts.fetch(prefix, 0)
        @counts[prefix] = count + 1

        dirname  = File.join(@root_dir, prefix)
        filename = File.join(@root_dir, prefix, count.to_s)

        FileUtils.mkdir_p(dirname)

        filename
      end

      # @param [String] prefix A string prefix that indicates which temporary
      #   filenames should be deleted.
      #
      # @return [void]
      def cleanup(prefix)
        path = File.join(@root_dir, prefix)
        if File.exist?(path)
          FileUtils.rm_rf(path)
        end

        @counts.delete(prefix)

        if @counts.empty? && File.directory?(@root_dir)
          FileUtils.rm_rf(@root_dir)
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09131238447319778, 'fraction_numerical': 0.0014787430683918669, 'mean_word_length': 2.399497487437186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1885051', 'n_tokens_mistral': 830, 'n_tokens_neox': 801, 'n_words': 231}