<commit_before>module Support
  module Constants
    extend ActiveSupport::Concern

    module ClassMethods
      def uses_constants(*constants)
        before { create_constants(*constants) }
      end
    end

    def create_constants(*constants)
      constants.each { |constant| create_constant(constant) }
    end

    def remove_constants(*constants)
      constants.each { |constant| remove_constant(constant) }
    end

    def create_constant(constant)
      remove_constant(constant)
      Kernel.const_set(constant, Model(constant))
    end

    def remove_constant(constant)
      Kernel.send(:remove_const, constant) if Kernel.const_defined?(constant)
    end

    def Model(name=nil)
      Class.new.tap do |model|
        model.class_eval """
          def self.name; '#{name}' end
          def self.to_s; '#{name}' end<commit_msg>Allow passing superclass to model and create_constant for specs.<commit_after>module Support
  module Constants
    extend ActiveSupport::Concern

    module ClassMethods
      def uses_constants(*constants)
        before { create_constants(*constants) }
      end
    end

    def create_constants(*constants)
      constants.each { |constant| create_constant(constant) }
    end

    def remove_constants(*constants)
      constants.each { |constant| remove_constant(constant) }
    end

    def create_constant(constant, superclass=nil)
      remove_constant(constant)
      Kernel.const_set(constant, Model(constant, superclass))
    end

    def remove_constant(constant)
      Kernel.send(:remove_const, constant) if Kernel.const_defined?(constant)
    end

    def Model(name=nil, superclass=nil)
      if superclass.nil?
        Class.new
      else
        Class.new(superclass)
      end.tap do |model|
        model.class_eval """
          def self.name; '#{name}' end
          def self.to_s; '#{name}' end
{'fraction_non_alphanumeric': 0.09051955008034279, 'fraction_numerical': 0.0, 'mean_word_length': 3.0085836909871246, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1650537', 'n_tokens_mistral': 533, 'n_tokens_neox': 533, 'n_words': 121}