<commit_before>require 'active_support/core_ext/string/inflections'
require 'rails_admin/generic_support'

module RailsAdmin
  class AbstractModel

    @models = []

    # Returns all models for a given Rails app
    def self.all
      if @models.empty?
        excluded_models = RailsAdmin::Config.excluded_models.map(&:to_s)
        excluded_models << ['History']

        # orig regexp -- found 'class' even if it's within a comment or a quote
        filenames = Dir.glob(Rails.application.paths.app.models.collect { |path| File.join(path, "**/*.rb") })
        class_names = []
        filenames.each do |filename|
          class_names += File.read(filename).scan(/class ([\w\d_\-:]+)/).flatten
        end
        possible_models = Module.constants | class_names
        #Rails.logger.info "possible_models: #{possible_models.inspect}"
        add_models(possible_models, excluded_models)

        #Rails.logger.info "final models: #{@models.map(&:model).inspect}"
        @models.sort!{|x, y| x.model.to_s <=> y.model.to_s}
      end

      @models
    end

    def self.add_models(possible_models=[], excluded_models=[])
      possible_models.each do |possible_model_name|
        next if excluded_models.include?(possible_model_name)
        #Rails.logger.info "possible_model_name: #{possible_model_name.inspect}"
        add_model(possible_model_name)
      end
    end

    def self.add_model(model_name)
      model = lookup(model_name,false)
      @models << new(model) if model
    end

    # Given a string +model_name+, finds the corresponding model class
    def self.lookup(model_name,raise_error=true)
      begin
        model = model_name.constantize
      rescue NameError
        #Rails.logger.info "#{model_name} wasn't a model"
        raise "RailsAdmin could not find model #{model_name}" if raise_error
        return nil
      end

      if model.is_a?(Class) && superclasses(model).include?(ActiveRecord::Base)<commit_msg>don't cache AbstractModel instances, only model names, this ensures classes are refreshed in development mode<commit_after>require 'active_support/core_ext/string/inflections'
require 'rails_admin/generic_support'

module RailsAdmin
  class AbstractModel

    @model_names = []

    # Returns all models for a given Rails app
    def self.all
      if @model_names.empty?
        excluded_models = RailsAdmin::Config.excluded_models.map(&:to_s)
        excluded_models << ['History']

        # orig regexp -- found 'class' even if it's within a comment or a quote
        filenames = Dir.glob(Rails.application.paths.app.models.collect { |path| File.join(path, "**/*.rb") })
        class_names = []
        filenames.each do |filename|
          class_names += File.read(filename).scan(/class ([\w\d_\-:]+)/).flatten
        end
        possible_models = Module.constants | class_names
        #Rails.logger.info "possible_models: #{possible_models.inspect}"
        models = (possible_models - excluded_models).map { |name| lookup(name, false) }

        #Rails.logger.info "final models: #{models.compact.inspect}"
        @model_names = models.compact.map(&:to_s).sort
      end

      @model_names.map { |name| new(name.constantize) }
    end

    # Given a string +model_name+, finds the corresponding model class
    def self.lookup(model_name,raise_error=true)
      begin
        model = model_name.constantize
      rescue NameError
        #Rails.logger.info "#{model_name} wasn't a model"
        raise "RailsAdmin could not find model #{model_name}" if raise_error
        return nil
      end

      if model.is_a?(Class) && superclasses(model).include?(ActiveRecord::Base)
{'fraction_non_alphanumeric': 0.11205712716286735, 'fraction_numerical': 0.0, 'mean_word_length': 3.0556792873051224, 'pattern_counts': {'":': 0, '<': 10, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5980983', 'n_tokens_mistral': 1106, 'n_tokens_neox': 1083, 'n_words': 253}