<commit_before>module TrustyCms
  autoload :Cache, 'trusty_cms/cache'

  class << self
    # Returns the TrustyCms::Config eigenclass object, so it can be used wherever you would use TrustyCms::Config.
    #
    #   TrustyCms.config['site.title']
    #   TrustyCms.config['site.url'] = 'example.com'
    #
    # but it will also yield itself to a block:
    #
    #   TrustyCms.config do |config|
    #     config.define 'something', default => 'something'
    #     config['other.thing'] = 'nothing'
    #   end
    #
    def config  # method must be defined before any initializers run
      yield TrustyCms::Config if block_given?
      TrustyCms::Config
    end

    # Returns the configuration object with which this application was initialized.
    # For now it's exactly the same as calling Rails.configuration except that it will also yield itself to a block.
    #
    def configuration
      yield Rails.configuration if block_given?
      Rails.configuration
    end

    # Returns the root directory of this radiant installation (which is usually the gem directory).
    # This is not the same as Rails.root, which is the instance directory and tends to contain only site-delivery material.
    #
    def root
      Pathname.new(TRUSTY_CMS_ROOT) if defined?(TRUSTY_CMS_ROOT)
    end
    def boot!
      unless booted?
        preinitialize
        pick_boot.run
      end
    end

    def booted?
      defined? TrustyCms::Initializer
    end

    def pick_boot
      case
        when app?
          AppBoot.new
        when vendor?
          VendorBoot.new
        else
          GemBoot.new
      end
    end

    def vendor?
      File.exist?("#{Rails.root}/vendor/radiant")
    end

    def app?
      File.exist?("#{Rails.root}/lib/radiant.rb")
    end

    def preinitialize
      load(preinitializer_path) if File.exist?(preinitializer_path)
    end

    def loaded_via_gem?
      pick_boot.is_a? GemBoot
    end

    def preinitializer_path
      "#{Rails.root}/config/preinitializer.rb"
    end
  end
end


class Rails::Application::Configuration

  # The TrustyCms::Configuration class extends Rails::Configuration with three purposes:
  # * to reset some rails defaults so that files are found in TRUSTY_CMS_ROOT instead of Rails.root
  # * to notice that some gems and plugins are in fact radiant extensions
  # * to notice that some radiant extensions add load paths (for plugins, controllers, metal, etc)

  attr_accessor :extension_paths, :ignored_extensions


  def load_trusty_paths
    #paths << ["#{TRUSTY_CMS_ROOT}/test/mocks/#{environment}"]

    # Add the app's controller directory
    #paths['app/controllers'].concat(Dir["#{TRUSTY_CMS_ROOT}/app/controllers/"])

    Dir["#{TRUSTY_CMS_ROOT}/lib/tasks/**/*.rake"].each { |ext| load ext } if defined?(Rake)

    # Followed by the standard includes.
    %w(
        app
        app/models
        app/controllers
        app/helpers
        app/views
        config
        lib
        vendor
      ).each  do |dir|
      autoload_paths.unshift "#{TRUSTY_CMS_ROOT}/#{dir}"
      $LOAD_PATH.unshift "#{TRUSTY_CMS_ROOT}/#{dir}"

      paths[dir] << "#{TRUSTY_CMS_ROOT}/#{dir}"
    end

    #paths.concat builtin_directories
  end

  def initialize_extension_paths
    self.extension_paths = default_extension_paths
    self.ignored_extensions = []
  end

  # Sets the locations in which we look for vendored extensions. Normally:
  #   Rails.root/vendor/extensions
  #   TrustyCms.root/vendor/extensions
  # There are no vendor/* directories in +TRUSTY_CMS_ROOT+ any more but the possibility remains for compatibility reasons.
  # In test mode we also add a fixtures path for testing the extension loader.
  #
  def default_extension_paths
    env = ENV["RAILS_ENV"] || Rails.env
    paths = [Rails.root + 'vendor/extensions']
    paths.unshift(TRUSTY_CMS_ROOT + "vendor/extensions") unless Rails.root == TRUSTY_CMS_ROOT
    paths
  end

  # The list of extensions, expanded and in load order, that results from combining all the extension
  # configuration directives. These are the extensions that will actually be loaded or migrated,
  # and for most purposes this is the list you want to refer to.
  #
  #   TrustyCms.configuration.enabled_extensions  # => [:name, :name, :name, :name]
  #
  # Note that an extension enabled is not the same as an extension activated or even loaded: it just means
  # that the application is configured to load that extension.
  #
  def enabled_extensions
    @enabled_extensions ||= expanded_extension_list - ignored_extensions
  end

  # The expanded and ordered list of extensions, including any that may later be ignored. This can be configured<commit_msg>Putting back a path config line I was too aggressive in removing<commit_after>module TrustyCms
  autoload :Cache, 'trusty_cms/cache'

  class << self
    # Returns the TrustyCms::Config eigenclass object, so it can be used wherever you would use TrustyCms::Config.
    #
    #   TrustyCms.config['site.title']
    #   TrustyCms.config['site.url'] = 'example.com'
    #
    # but it will also yield itself to a block:
    #
    #   TrustyCms.config do |config|
    #     config.define 'something', default => 'something'
    #     config['other.thing'] = 'nothing'
    #   end
    #
    def config  # method must be defined before any initializers run
      yield TrustyCms::Config if block_given?
      TrustyCms::Config
    end

    # Returns the configuration object with which this application was initialized.
    # For now it's exactly the same as calling Rails.configuration except that it will also yield itself to a block.
    #
    def configuration
      yield Rails.configuration if block_given?
      Rails.configuration
    end

    # Returns the root directory of this radiant installation (which is usually the gem directory).
    # This is not the same as Rails.root, which is the instance directory and tends to contain only site-delivery material.
    #
    def root
      Pathname.new(TRUSTY_CMS_ROOT) if defined?(TRUSTY_CMS_ROOT)
    end
    def boot!
      unless booted?
        preinitialize
        pick_boot.run
      end
    end

    def booted?
      defined? TrustyCms::Initializer
    end

    def pick_boot
      case
        when app?
          AppBoot.new
        when vendor?
          VendorBoot.new
        else
          GemBoot.new
      end
    end

    def vendor?
      File.exist?("#{Rails.root}/vendor/radiant")
    end

    def app?
      File.exist?("#{Rails.root}/lib/radiant.rb")
    end

    def preinitialize
      load(preinitializer_path) if File.exist?(preinitializer_path)
    end

    def loaded_via_gem?
      pick_boot.is_a? GemBoot
    end

    def preinitializer_path
      "#{Rails.root}/config/preinitializer.rb"
    end
  end
end


class Rails::Application::Configuration

  # The TrustyCms::Configuration class extends Rails::Configuration with three purposes:
  # * to reset some rails defaults so that files are found in TRUSTY_CMS_ROOT instead of Rails.root
  # * to notice that some gems and plugins are in fact radiant extensions
  # * to notice that some radiant extensions add load paths (for plugins, controllers, metal, etc)

  attr_accessor :extension_paths, :ignored_extensions


  def load_trusty_paths
    #paths << ["#{TRUSTY_CMS_ROOT}/test/mocks/#{environment}"]

    # Add the app's controller directory
    #paths['app/controllers'].concat(Dir["#{TRUSTY_CMS_ROOT}/app/controllers/"])

    Dir["#{TRUSTY_CMS_ROOT}/lib/tasks/**/*.rake"].each { |ext| load ext } if defined?(Rake)

    # Followed by the standard includes.
    %w(
        app
        app/models
        app/controllers
        app/helpers
        app/views
        config
        lib
        vendor
      ).each  do |dir|
      autoload_paths.unshift "#{TRUSTY_CMS_ROOT}/#{dir}"
      $LOAD_PATH.unshift "#{TRUSTY_CMS_ROOT}/#{dir}"

      paths[dir] << "#{TRUSTY_CMS_ROOT}/#{dir}"
    end

    #paths.concat builtin_directories
  end

  def initialize_extension_paths
    self.extension_paths = default_extension_paths
    self.ignored_extensions = []
  end

  # Sets the locations in which we look for vendored extensions. Normally:
  #   Rails.root/vendor/extensions
  #   TrustyCms.root/vendor/extensions
  # There are no vendor/* directories in +TRUSTY_CMS_ROOT+ any more but the possibility remains for compatibility reasons.
  # In test mode we also add a fixtures path for testing the extension loader.
  #
  def default_extension_paths
    env = ENV["RAILS_ENV"] || Rails.env
    paths = [Rails.root + 'vendor/extensions']
    paths.unshift(TRUSTY_CMS_ROOT + "vendor/extensions") unless Rails.root == TRUSTY_CMS_ROOT
    paths.unshift(TRUSTY_CMS_ROOT + "test/fixtures/extensions") if env =~ /test/
    paths
  end

  # The list of extensions, expanded and in load order, that results from combining all the extension
  # configuration directives. These are the extensions that will actually be loaded or migrated,
  # and for most purposes this is the list you want to refer to.
  #
  #   TrustyCms.configuration.enabled_extensions  # => [:name, :name, :name, :name]
  #
  # Note that an extension enabled is not the same as an extension activated or even loaded: it just means
  # that the application is configured to load that extension.
  #
  def enabled_extensions
    @enabled_extensions ||= expanded_extension_list - ignored_extensions
  end

  # The expanded and ordered list of extensions, including any that may later be ignored. This can be configured
{'fraction_non_alphanumeric': 0.08050579557428872, 'fraction_numerical': 0.0, 'mean_word_length': 2.96118530884808, 'pattern_counts': {'":': 0, '<': 15, '<?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': '1788131', 'n_tokens_mistral': 2848, 'n_tokens_neox': 2744, 'n_words': 909}