<commit_before>tables = ActiveRecord::Base.connection.tables

tables.each_with_index do |table, index|
  klass = table.class_name
  puts klass.column_names
end

# Add all Models
classes = []
ObjectSpace.each_object(Class) do |c|
  classes << c if c.superclass == ActiveRecord::Base
end

classes[].reflections.keys.each do |key|
  Post.reflections["comments"].table_name # => "comments"
  Post.reflections["comments"].macro # => :has_many
  Post.reflections["comments"].foreign_key # => "message_id"
end

classes[0]
classes[0].reflections
# cards
classes[0].reflections["cards"].macro
# :has_many<commit_msg>done for the first time<commit_after># Rails 4 = ActiveRecord::Base
# Rails 5 = ApplicationRecord

# Post.reflections["comments"].table_name # => "comments"
# Post.reflections["comments"].macro # => :has_many
# Post.reflections["comments"].foreign_key # => "message_id"

def get_rails_version
  Rails::VERSION::STRING[0]
end

def print_all_models version
  if ActiveRecord::Base.subclasses.size > 0
    # Rails 4
    if version == "4"
      models = ObjectSpace.each_object(Class).select { |o| o.superclass == ActiveRecord::Base }

      models.each do |model|
        puts model
        model.reflections.keys.each do |key|
          puts "\t#{model.reflections[key].macro} #{key.capitalize} #{model.reflections[key].foreign_key}"
        end
      end
    # Rails 5
    elsif version == "5"
      models = ObjectSpace.each_object(Class).select { |o| o.superclass == ApplicationRecord }

      models.each do |model|
        puts model
        model.reflections.keys.each do |key|
            puts "\t#{model.reflections[key].macro} #{key.capitalize} #{model.reflections[key].foreign_key}"
        end
      end
    end
  else
    puts "There are no any models in this project!"
  end
end

def print_all_tables version
  # Rails 4
  if version == "4"
    tables = ActiveRecord::Base.connection.tables

    tables.each_with_index do |table, index|
      puts table.class_name.column_names
    end
  end
end

print_all_models get_rails_version
{'fraction_non_alphanumeric': 0.12396290873596877, 'fraction_numerical': 0.00634455832113226, 'mean_word_length': 3.7235023041474653, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3167344', 'n_tokens_mistral': 666, 'n_tokens_neox': 648, 'n_words': 147}