<commit_before>class SubsetValidator < ActiveModel::EachValidator
  @@error_message = 'contains an invalid value'

  def validate_each(record, attribute, value)
    unless options[:in].respond_to? :include?
      raise ArgumentError, 'An object with the method include? must be supplied as the :in option of the configuration hash'
    end

    unless value.respond_to? :each
      raise ArgumentError, 'The attribute being validated must respond to #each'
    end

    error_message = options[:message] || @@error_message

    value.each do |element|
      unless options[:in].include? element
        record.errors.add attribute, error_message
        break
      end<commit_msg>Added documentation to #validate_each .<commit_after>class SubsetValidator < ActiveModel::EachValidator
  @@error_message = 'contains an invalid value'

  # Validate that the specified attribute's value is a subset of another set.
  #
  # Note that this works on more than just arrays, too. It'll work on anything, provided that:
  # * the attribute's value can be anything that responds to <i>#each</i> ;
  # * the set of valid values can be anything that responds to <i>#include?</i> .
  #
  # @example
  #   class User
  #     include ActiveModel::Validations
  #
  #     attr_accessor :roles
  #
  #     @@valid_roles = %w(admin manager developer)
  #
  #     validates :roles, :subset => {:in => @@valid_roles}
  #   end
  #
  #   u       = User.new
  #   u.roles = %w(admin something_else)
  #
  #   u.valid?
  #    => false
  #   u.errors
  #    => {:roles=>["contains an invalid value"]}
  #
  #   u.roles = %w(admin)
  #   u.valid?
  #    => true
  def validate_each(record, attribute, value)
    unless options[:in].respond_to? :include?
      raise ArgumentError, 'An object with the method include? must be supplied as the :in option of the configuration hash'
    end

    unless value.respond_to? :each
      raise ArgumentError, 'The attribute being validated must respond to #each'
    end

    error_message = options[:message] || @@error_message

    value.each do |element|
      unless options[:in].include? element
        record.errors.add attribute, error_message
        break
      end
{'fraction_non_alphanumeric': 0.09812870835235052, 'fraction_numerical': 0.0, 'mean_word_length': 3.1203007518796992, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '1169403', 'n_tokens_mistral': 654, 'n_tokens_neox': 631, 'n_words': 212}