<commit_before>require 'md5'
require 'fileutils'
module FixtureBuilder
  class << self
    def configuration
      @configuration ||= FixtureBuilder::Configuration.new
    end
    
    def configure
      yield configuration
    end
  end

  class Configuration
    attr_accessor :select_sql, :delete_sql, :skip_tables, :files_to_check, :record_name_fields, :fixture_builder_file

    def initialize
      @custom_names = {}
      @file_hashes = file_hashes
    end

    def select_sql
      @select_sql ||= "SELECT * FROM `%s`"
    end

    def delete_sql
      @delete_sql ||= "DELETE FROM `%s`"
    end

    def skip_tables
      @skip_table ||= %w{ schema_migrations }
    end

    def files_to_check
      @files_to_check ||= %w{ db/schema.rb }
    end

    def record_name_fields
      @record_name_fields ||= %w{ unique_name display_name name title username login }
    end

    def fixture_builder_file
      @fixture_builder_file ||= Rails.root.join('tmp', 'fixture_builder.yml')
    end

    def factory
      return unless rebuild_fixtures?
      say "Building fixtures"
      delete_tables
      surface_errors { yield }
      FileUtils.rm_rf(Rails.root.join(spec_or_test_dir, 'fixtures', '*.yml'))
      dump_empty_fixtures_for_all_tables
      dump_tables
      write_config
    end
  
    private
  
    def say(*messages)
      puts messages.map { |message| "=> #{message}" }
    end

    def surface_errors
      yield
    rescue Object => error
      puts
      say "There was an error building fixtures", error.inspect
      puts
      puts error.backtrace
      puts
      exit!
    end

    def delete_tables
      tables.each { |t| ActiveRecord::Base.connection.delete(delete_sql % t)  }
    end

    def tables
      ActiveRecord::Base.connection.tables - skip_tables
    end

    def name(custom_name, model_object)
      key = [model_object.class.name, model_object.id]
      @custom_names[key] = custom_name
      model_object
    end
<commit_msg>when files_to_check changes we must rebuild the file_hashes<commit_after>require 'md5'
require 'fileutils'
module FixtureBuilder
  class << self
    def configuration
      @configuration ||= FixtureBuilder::Configuration.new
    end

    def configure
      yield configuration
    end
  end

  class Configuration
    attr_accessor :select_sql, :delete_sql, :skip_tables, :files_to_check, :record_name_fields, :fixture_builder_file

    def initialize
      @custom_names = {}
      @file_hashes = file_hashes
    end

    def select_sql
      @select_sql ||= "SELECT * FROM `%s`"
    end

    def delete_sql
      @delete_sql ||= "DELETE FROM `%s`"
    end

    def skip_tables
      @skip_table ||= %w{ schema_migrations }
    end

    def files_to_check
      @files_to_check ||= %w{ db/schema.rb }
    end

    def files_to_check=(files)
      @files_to_check = files
      @file_hashes = file_hashes
      @files_to_check
    end

    def record_name_fields
      @record_name_fields ||= %w{ unique_name display_name name title username login }
    end

    def fixture_builder_file
      @fixture_builder_file ||= Rails.root.join('tmp', 'fixture_builder.yml')
    end

    def factory
      return unless rebuild_fixtures?
      say "Building fixtures"
      delete_tables
      surface_errors { yield }
      FileUtils.rm_rf(Rails.root.join(spec_or_test_dir, 'fixtures', '*.yml'))
      dump_empty_fixtures_for_all_tables
      dump_tables
      write_config
    end

    private

    def say(*messages)
      puts messages.map { |message| "=> #{message}" }
    end

    def surface_errors
      yield
    rescue Object => error
      puts
      say "There was an error building fixtures", error.inspect
      puts
      puts error.backtrace
      puts
      exit!
    end

    def delete_tables
      tables.each { |t| ActiveRecord::Base.connection.delete(delete_sql % t)  }
    end

    def tables
      ActiveRecord::Base.connection.tables - skip_tables
    end

    def name(custom_name, model_object)
      key = [model_object.class.name, model_object.id]
      @custom_names[key] = custom_name
      model_object
    end

{'fraction_non_alphanumeric': 0.08128498418106596, 'fraction_numerical': 0.0004867364322219518, 'mean_word_length': 2.6533333333333333, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1642989', 'n_tokens_mistral': 1308, 'n_tokens_neox': 1276, 'n_words': 307}