<commit_before># frozen_string_literal: true

require "zeitwerk"
require "byebug" if ENV["METAL_ARCHIVES_ENV"] == "development"
require "active_support/all"

##
# Metal Archives Ruby API
#
module MetalArchives
  class << self
    # Code loader instance
    attr_reader :loader

    ##
    # Root path
    #
    def root
      @root ||= Pathname.new(File.expand_path(File.join("..", ".."), __FILE__))
    end

    ##
    # HTTP client
    #
    def http
      @http ||= HTTPClient.new
    end

    ##
    # API configuration
    #
    # Instance of rdoc-ref:MetalArchives::Configuration
    #
    def config
      raise MetalArchives::Errors::InvalidConfigurationError, "Gem has not been configured" unless @config

      @config
    end

    ##
    # Cache instance
    #
    def cache
      raise MetalArchives::Errors::InvalidConfigurationError, "cache has not been configured" unless config.cache_strategy

      @cache ||= Cache.const_get(loader.inflector.camelize(config.cache_strategy, root))
    end

    ##
    # Configure API options.
    #
    # A block must be specified, to which a
    # rdoc-ref:MetalArchives::Configuration parameter will be passed.
    #
    # [Raises]
    # - rdoc-ref:InvalidConfigurationException
    #
    def configure
      raise Errors::InvalidConfigurationError, "no configuration block given" unless block_given?

      @config = Configuration.new
      yield config

      config.validate!
    end

    ##
    # Set up application framework
    #
    def setup
      @loader = Zeitwerk::Loader.for_gem

      # Register inflections
      require root.join("config/inflections.rb")

      # Set up code loader
      loader.enable_reloading if ENV["METAL_ARCHIVES_ENV"] == "development"
      loader.collapse(root.join("lib/metal_archives/models"))
      loader.do_not_eager_load(root.join("lib/metal_archives/cache"))
      loader.setup<commit_msg>Do not overwrite earlier configurations<commit_after># frozen_string_literal: true

require "zeitwerk"
require "byebug" if ENV["METAL_ARCHIVES_ENV"] == "development"
require "active_support/all"

##
# Metal Archives Ruby API
#
module MetalArchives
  class << self
    # Code loader instance
    attr_reader :loader

    ##
    # Root path
    #
    def root
      @root ||= Pathname.new(File.expand_path(File.join("..", ".."), __FILE__))
    end

    ##
    # HTTP client
    #
    def http
      @http ||= HTTPClient.new
    end

    ##
    # API configuration
    #
    # Instance of rdoc-ref:MetalArchives::Configuration
    #
    def config
      @config ||= Configuration.new
    end

    ##
    # Cache instance
    #
    def cache
      raise MetalArchives::Errors::InvalidConfigurationError, "cache has not been configured" unless config.cache_strategy

      @cache ||= Cache.const_get(loader.inflector.camelize(config.cache_strategy, root))
    end

    ##
    # Configure API options.
    #
    # A block must be specified, to which a
    # rdoc-ref:MetalArchives::Configuration parameter will be passed.
    #
    # [Raises]
    # - rdoc-ref:InvalidConfigurationException
    #
    def configure
      raise Errors::InvalidConfigurationError, "no configuration block given" unless block_given?

      yield config

      config.validate!
    end

    ##
    # Set up application framework
    #
    def setup
      @loader = Zeitwerk::Loader.for_gem

      # Register inflections
      require root.join("config/inflections.rb")

      # Set up code loader
      loader.enable_reloading if ENV["METAL_ARCHIVES_ENV"] == "development"
      loader.collapse(root.join("lib/metal_archives/models"))
      loader.do_not_eager_load(root.join("lib/metal_archives/cache"))
      loader.setup
{'fraction_non_alphanumeric': 0.1007057546145494, 'fraction_numerical': 0.0, 'mean_word_length': 2.8385416666666665, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3179665', 'n_tokens_mistral': 1122, 'n_tokens_neox': 1091, 'n_words': 257}