<commit_before>require 'pathname'
require 'json'
require 'hanami/utils/string'
require 'hanami/utils/class'
require 'hanami/utils/path_prefix'
require 'hanami/utils/basic_object'
require 'hanami/assets/config/manifest'
require 'hanami/assets/config/sources'

module Hanami
  module Assets
    # Framework configuration
    #
    # @since 0.1.0
    class Configuration # rubocop:disable Metrics/ClassLength
      # @since 0.1.0
      # @api private
      DEFAULT_SCHEME                          = 'http'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_HOST                            = 'localhost'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_PORT                            = '2300'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_PUBLIC_DIRECTORY                = 'public'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_MANIFEST                        = 'assets.json'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_PREFIX                          = '/assets'.freeze

      # @since 0.1.0
      # @api private
      URL_SEPARATOR                           = '/'.freeze

      # @since 0.1.0
      # @api private
      HTTP_SCHEME                             = 'http'.freeze

      # @since 0.1.0
      # @api private
      HTTP_PORT                               = '80'.freeze

      # @since 0.1.0
      # @api private
      HTTPS_SCHEME                            = 'https'.freeze

      # @since 0.1.0
      # @api private
      HTTPS_PORT                              = '443'.freeze

      # @since 0.3.0
      # @api private
      DEFAULT_SUBRESOURCE_INTEGRITY_ALGORITHM = :sha256

      # @since 0.3.0
      # @api private
      SUBRESOURCE_INTEGRITY_SEPARATOR         = ' '.freeze

      # Return a copy of the configuration of the framework instance associated
      # with the given class.
      #
      # When multiple instances of Hanami::Assets are used in the same
      # application, we want to make sure that a controller or an action will
      # receive the expected configuration.
      #
      # @param base [Class, Module] a controller or an action
      #
      # @return [Hanami::Assets::Configuration] the configuration associated
      #   to the given class.
      #
      # @since 0.1.0
      # @api private
      def self.for(base)
        # TODO: this implementation is similar to Hanami::Controller::Configuration consider to extract it into Hanami::Utils
        namespace = Utils::String.namespace(base)
        framework = Utils::Class.load_from_pattern!("(#{namespace}|Hanami)::Assets")
        framework.configuration
      end

      # @since 0.4.0
      # @api private
      attr_reader :public_manifest

      # Return a new instance
      #
      # @return [Hanami::Assets::Configuration] a new instance
      #
      # @since 0.1.0
      # @api private
      def initialize(&blk)
        reset!
        instance_eval(&blk) if block_given?
      end

      # Compile mode
      #
      # Determine if compile assets from sources to destination.
      # Usually this is turned off in production mode.
      #
      # @since 0.1.0
      def compile(value = nil)
        if value.nil?
          @compile<commit_msg>Remove Utils::Class.load_from_pattern! usage (#90)<commit_after>require 'pathname'
require 'json'
require 'hanami/utils/string'
require 'hanami/utils/class'
require 'hanami/utils/path_prefix'
require 'hanami/utils/basic_object'
require 'hanami/assets/config/manifest'
require 'hanami/assets/config/sources'

module Hanami
  module Assets
    # Framework configuration
    #
    # @since 0.1.0
    class Configuration # rubocop:disable Metrics/ClassLength
      # @since 0.1.0
      # @api private
      DEFAULT_SCHEME                          = 'http'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_HOST                            = 'localhost'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_PORT                            = '2300'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_PUBLIC_DIRECTORY                = 'public'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_MANIFEST                        = 'assets.json'.freeze

      # @since 0.1.0
      # @api private
      DEFAULT_PREFIX                          = '/assets'.freeze

      # @since 0.1.0
      # @api private
      URL_SEPARATOR                           = '/'.freeze

      # @since 0.1.0
      # @api private
      HTTP_SCHEME                             = 'http'.freeze

      # @since 0.1.0
      # @api private
      HTTP_PORT                               = '80'.freeze

      # @since 0.1.0
      # @api private
      HTTPS_SCHEME                            = 'https'.freeze

      # @since 0.1.0
      # @api private
      HTTPS_PORT                              = '443'.freeze

      # @since 0.3.0
      # @api private
      DEFAULT_SUBRESOURCE_INTEGRITY_ALGORITHM = :sha256

      # @since 0.3.0
      # @api private
      SUBRESOURCE_INTEGRITY_SEPARATOR         = ' '.freeze

      # Return a copy of the configuration of the framework instance associated
      # with the given class.
      #
      # When multiple instances of Hanami::Assets are used in the same
      # application, we want to make sure that a controller or an action will
      # receive the expected configuration.
      #
      # @param base [Class, Module] a controller or an action
      #
      # @return [Hanami::Assets::Configuration] the configuration associated
      #   to the given class.
      #
      # @since 0.1.0
      # @api private
      def self.for(base)
        # TODO: this implementation is similar to Hanami::Controller::Configuration consider to extract it into Hanami::Utils
        namespace = Utils::String.namespace(base)
        framework = Utils::Class.load("#{namespace}::Assets") || Utils::Class.load!('Hanami::Assets')
        framework.configuration
      end

      # @since 0.4.0
      # @api private
      attr_reader :public_manifest

      # Return a new instance
      #
      # @return [Hanami::Assets::Configuration] a new instance
      #
      # @since 0.1.0
      # @api private
      def initialize(&blk)
        reset!
        instance_eval(&blk) if block_given?
      end

      # Compile mode
      #
      # Determine if compile assets from sources to destination.
      # Usually this is turned off in production mode.
      #
      # @since 0.1.0
      def compile(value = nil)
        if value.nil?
          @compile
{'fraction_non_alphanumeric': 0.09178669935642048, 'fraction_numerical': 0.02053325160894882, 'mean_word_length': 1.6554109031733117, 'pattern_counts': {'":': 0, '<': 3, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5880692', 'n_tokens_mistral': 1959, 'n_tokens_neox': 1860, 'n_words': 489}