<commit_before># Adds ::validates and friends, and #valid? to the object.
# This is completely form-independent.
module Reform::Validation
  module ClassMethods
    def validation_groups
      @groups ||= Groups.new(validation_group_class) # TODO: inheritable_attr with Inheritable::Hash
    end

    # DSL.
    def validation(name=:default, options={}, &block)
      heritage.record(:validation, name, options, &block)

      options = deprecate_validation_positional_args(name, options)
      name    = options[:name] # TODO: remove in favor of kw args in 3.0.

      group = validation_groups.add(name, options)

      group.instance_exec(&block)
    end

    def deprecate_validation_positional_args(name, options)
      if name.is_a?(Symbol)
        warn "[Reform] Form::validation API is now: validation(name: :default, if:nil, schema:Schema). Please use keyword arguments instead of positional arguments."
        return { name: name }.merge(options)<commit_msg>ensure heritage uses the resolved name (same as validation group) from hash or positional args<commit_after># Adds ::validates and friends, and #valid? to the object.
# This is completely form-independent.
module Reform::Validation
  module ClassMethods
    def validation_groups
      @groups ||= Groups.new(validation_group_class) # TODO: inheritable_attr with Inheritable::Hash
    end

    # DSL.
    def validation(name=:default, options={}, &block)
      options = deprecate_validation_positional_args(name, options)
      name    = options[:name] # TODO: remove in favor of kw args in 3.0.

      heritage.record(:validation, name, options, &block)
      group = validation_groups.add(name, options)

      group.instance_exec(&block)
    end

    def deprecate_validation_positional_args(name, options)
      if name.is_a?(Symbol)
        warn "[Reform] Form::validation API is now: validation(name: :default, if:nil, schema:Schema). Please use keyword arguments instead of positional arguments."
        return { name: name }.merge(options)
{'fraction_non_alphanumeric': 0.09712586719524281, 'fraction_numerical': 0.0019821605550049554, 'mean_word_length': 3.9729064039408866, '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': '2725840', 'n_tokens_mistral': 573, 'n_tokens_neox': 549, 'n_words': 177}