<commit_before>require 'bigdecimal'
require 'date'
require 'set'

require 'inflecto'
require 'thread_safe'

require 'dry-container'
require 'dry-equalizer'

require 'dry/types/version'
require 'dry/types/container'
require 'dry/types/definition'
require 'dry/types/constructor'
require 'dry/types/struct'
require 'dry/types/value'

module Dry
  module Types
    extend Dry::Configurable

    setting :namespace, self

    class SchemaError < TypeError
      def initialize(key, value)
        super("#{value.inspect} (#{value.class}) has invalid type for :#{key}")
      end
    end

    class SchemaKeyError < KeyError
      def initialize(key)
        super(":#{key} is missing in Hash input")
      end
    end

    StructError = Class.new(TypeError)
    ConstraintError = Class.new(TypeError)

    TYPE_SPEC_REGEX = %r[(.+)<(.+)>].freeze

    def self.module
      namespace = Module.new
      define_constants(namespace, type_keys)
      namespace
    end

    def self.finalize
      warn 'Dry::Types.finalize and configuring namespace is deprecated. Just'\
       ' do `include Dry::Types.module` in places where you want to have access'\
       ' to built-in types'

      define_constants(config.namespace, type_keys)
    end

    def self.container
      @container ||= Container.new
    end

    def self.register(name, type = nil, &block)
      container.register(name, type || block.call)
    end

    def self.register_class(klass)
      container.register(
        Inflecto.underscore(klass).tr('/', '.'),
        Constructor.new(Definition.new(klass), fn: klass.method(:new))
      )
    end

    def self.[](name)
      type_map.fetch_or_store(name) do
        case name
        when String
          result = name.match(TYPE_SPEC_REGEX)

          if result<commit_msg>Clean up Types.register_class<commit_after>require 'bigdecimal'
require 'date'
require 'set'

require 'inflecto'
require 'thread_safe'

require 'dry-container'
require 'dry-equalizer'

require 'dry/types/version'
require 'dry/types/container'
require 'dry/types/definition'
require 'dry/types/constructor'
require 'dry/types/struct'
require 'dry/types/value'

module Dry
  module Types
    extend Dry::Configurable

    setting :namespace, self

    class SchemaError < TypeError
      def initialize(key, value)
        super("#{value.inspect} (#{value.class}) has invalid type for :#{key}")
      end
    end

    class SchemaKeyError < KeyError
      def initialize(key)
        super(":#{key} is missing in Hash input")
      end
    end

    StructError = Class.new(TypeError)
    ConstraintError = Class.new(TypeError)

    TYPE_SPEC_REGEX = %r[(.+)<(.+)>].freeze

    def self.module
      namespace = Module.new
      define_constants(namespace, type_keys)
      namespace
    end

    def self.finalize
      warn 'Dry::Types.finalize and configuring namespace is deprecated. Just'\
       ' do `include Dry::Types.module` in places where you want to have access'\
       ' to built-in types'

      define_constants(config.namespace, type_keys)
    end

    def self.container
      @container ||= Container.new
    end

    def self.register(name, type = nil, &block)
      container.register(name, type || block.call)
    end

    def self.register_class(klass)
      type = Definition.new(klass).constructor(klass.method(:new))
      container.register(identifier(klass), type)
    end

    def self.[](name)
      type_map.fetch_or_store(name) do
        case name
        when String
          result = name.match(TYPE_SPEC_REGEX)

          if result
{'fraction_non_alphanumeric': 0.1072333239515902, 'fraction_numerical': 0.0, 'mean_word_length': 2.9054945054945054, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 5, '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': '4354412', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1060, 'n_words': 276}