<commit_before>module SpecProducer::FactoriesProductionModule
  def self.produce_factories
    Dir.glob(Rails.root.join('app/models/*.rb')).each do |x|
      require x
    end

    not_valid_descendants = [ ActiveRecord::SchemaMigration ]

    if Object.const_defined?('Delayed')
      not_valid_descendants << Delayed::Backend::ActiveRecord::Job
    end

    ActiveRecord::Base.descendants.reject { |descendant| not_valid_descendants.include? descendant }.each do |descendant|
      final_text = "FactoryGirl.define do\n"
      final_text << "  factory :#{descendant.name.underscore}, :class => #{descendant.name} do\n"

      descendant.columns.each do |column|
        value = case column.type
                  when :string then "'#{descendant.name.underscore.upcase}_#{column.name.underscore.upcase}'"
                  when :text then "'#{descendant.name.underscore.upcase}_#{column.name.underscore.upcase}'"
                  when :integer then "#{rand(1...10)}"
                  when :decimal then "#{rand(1.0...100.0)}"
                  when :float then "#{rand(1.0...100.0)}"
                  when :datetime then "'#{DateTime.now + 365}'"
                  when :time then "'#{Time.now + 365*24*60*60}'"
                  when :date then "'#{Date.today + 365}'"
                  when :boolean then "#{rand(2) == 1 ? true : false}"
                  when :binary then "#{5.times.collect { rand(0..1).to_s }.join('')}"
                end

        final_text << "    #{column.name} #{value}\n"
      end

      final_text << "  end\n"
      final_text << "end"

      if File.exists?(Rails.root.join("spec/factories/#{descendant.name.underscore}.rb"))
        puts '#'*100
        puts "Please, check whether the following lines are included in: spec/factories/" + descendant.name.underscore + ".rb\n"
        puts '#'*100
        puts "\n"
        puts final_text
      else
        unless Dir.exists? Rails.root.join("spec")
          puts "Generating spec directory"
          Dir.mkdir(Rails.root.join("spec"))
        end

        unless Dir.exists? Rails.root.join("spec/factories")
          puts "Generating spec/factories directory"
          Dir.mkdir(Rails.root.join("spec/factories"))
        end

        path = "spec/factories/#{descendant.name.underscore}.rb"
        puts "Producing factory file for: #{path}"
        f = File.open("#{Rails.root.join(path)}", 'wb+')
        f.write(final_text)
        f.close
      end
    end

    nil
  rescue NameError
    puts "ActiveRecord is not set for this project. Can't produce factories for this project."
  rescue Exception => e
    puts "Exception '#{e}' was raised. Skipping factories production."
  end
end<commit_msg>Log name error.<commit_after>module SpecProducer::FactoriesProductionModule
  def self.produce_factories
    Dir.glob(Rails.root.join('app/models/*.rb')).each do |x|
      require x
    end

    not_valid_descendants = [ ActiveRecord::SchemaMigration ]

    if Object.const_defined?('Delayed')
      not_valid_descendants << Delayed::Backend::ActiveRecord::Job
    end

    ActiveRecord::Base.descendants.reject { |descendant| not_valid_descendants.include? descendant }.each do |descendant|
      final_text = "FactoryGirl.define do\n"
      final_text << "  factory :#{descendant.name.underscore}, :class => #{descendant.name} do\n"

      descendant.columns.each do |column|
        value = case column.type
                  when :string then "'#{descendant.name.underscore.upcase}_#{column.name.underscore.upcase}'"
                  when :text then "'#{descendant.name.underscore.upcase}_#{column.name.underscore.upcase}'"
                  when :integer then "#{rand(1...10)}"
                  when :decimal then "#{rand(1.0...100.0)}"
                  when :float then "#{rand(1.0...100.0)}"
                  when :datetime then "'#{DateTime.now + 365}'"
                  when :time then "'#{Time.now + 365*24*60*60}'"
                  when :date then "'#{Date.today + 365}'"
                  when :boolean then "#{rand(2) == 1 ? true : false}"
                  when :binary then "#{5.times.collect { rand(0..1).to_s }.join('')}"
                end

        final_text << "    #{column.name} #{value}\n"
      end

      final_text << "  end\n"
      final_text << "end"

      if File.exists?(Rails.root.join("spec/factories/#{descendant.name.underscore}.rb"))
        puts '#'*100
        puts "Please, check whether the following lines are included in: spec/factories/" + descendant.name.underscore + ".rb\n"
        puts '#'*100
        puts "\n"
        puts final_text
      else
        unless Dir.exists? Rails.root.join("spec")
          puts "Generating spec directory"
          Dir.mkdir(Rails.root.join("spec"))
        end

        unless Dir.exists? Rails.root.join("spec/factories")
          puts "Generating spec/factories directory"
          Dir.mkdir(Rails.root.join("spec/factories"))
        end

        path = "spec/factories/#{descendant.name.underscore}.rb"
        puts "Producing factory file for: #{path}"
        f = File.open("#{Rails.root.join(path)}", 'wb+')
        f.write(final_text)
        f.close
      end
    end

    nil
  rescue NameError => e
    puts "NameError '#{e}' was raised. Can't produce factories for this project."
  rescue Exception => e
    puts "Exception '#{e}' was raised. Skipping factories production."
  end
end
{'fraction_non_alphanumeric': 0.1422205718529521, 'fraction_numerical': 0.015224656516895656, 'mean_word_length': 2.3397396156230625, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 8, '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': '2551990', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1642, 'n_words': 365}