<commit_before>module BitmaskAttributes
  class Definition
    attr_reader :attribute, :values, :extension
    
    def initialize(attribute, values=[], &extension)
      @attribute = attribute
      @values = values
      @extension = extension
    end
    
    def install_on(model)
      validate_for model
      generate_bitmasks_on model
      override model
      create_convenience_class_method_on model
      create_convenience_instance_methods_on model
      create_scopes_on model
      create_attribute_methods_on model
    end
    
    private

      def validate_for(model)
        # The model cannot be validated if it is preloaded and the attribute/column is not in the
        # database (the migration has not been run).  This usually
        # occurs in the 'test' and 'production' environments.
        return if defined?(Rails) && Rails.configuration.cache_classes

        unless model.columns.detect { |col| col.name == attribute.to_s }
          raise ArgumentError, "`#{attribute}' is not an attribute of `#{model}'"
        end
      end
    
      def generate_bitmasks_on(model)
        model.bitmasks[attribute] = HashWithIndifferentAccess.new.tap do |mapping|
          values.each_with_index do |value, index|
            mapping[value] = 0b1 << index
          end
        end
      end
    
      def override(model)
        override_getter_on(model)
        override_setter_on(model)
      end
    
      def override_getter_on(model)<commit_msg>don't validate attribute during creating table<commit_after>module BitmaskAttributes
  class Definition
    attr_reader :attribute, :values, :extension
    
    def initialize(attribute, values=[], &extension)
      @attribute = attribute
      @values = values
      @extension = extension
    end
    
    def install_on(model)
      validate_for model
      generate_bitmasks_on model
      override model
      create_convenience_class_method_on model
      create_convenience_instance_methods_on model
      create_scopes_on model
      create_attribute_methods_on model
    end
    
    private

      def validate_for(model)
        # The model cannot be validated if it is preloaded and the attribute/column is not in the
        # database (the migration has not been run) or table doesn't exist. This usually
        # occurs in the 'test' and 'production' environment or during migration.
        return if defined?(Rails) && Rails.configuration.cache_classes || !model.table_exists?
       
        unless model.columns.detect { |col| col.name == attribute.to_s }
          raise ArgumentError, "`#{attribute}' is not an attribute of `#{model}'"
        end
      end
    
      def generate_bitmasks_on(model)
        model.bitmasks[attribute] = HashWithIndifferentAccess.new.tap do |mapping|
          values.each_with_index do |value, index|
            mapping[value] = 0b1 << index
          end
        end
      end
    
      def override(model)
        override_getter_on(model)
        override_setter_on(model)
      end
    
      def override_getter_on(model)
{'fraction_non_alphanumeric': 0.0643160300359125, 'fraction_numerical': 0.001305909239307868, 'mean_word_length': 2.5381062355658197, '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': '6942970', 'n_tokens_mistral': 840, 'n_tokens_neox': 829, 'n_words': 242}