Class: ActiveModel::Validations::FormatValidator

Inherits:
EachValidator show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/validations/format.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from EachValidator

#attributes

Attributes inherited from ActiveModel::Validator

#options

Instance Method Summary collapse

Methods inherited from EachValidator

#initialize, #validate

Methods inherited from ActiveModel::Validator

#initialize, kind, #kind, #validate

Constructor Details

This class inherits a constructor from ActiveModel::EachValidator

Instance Method Details

#check_validity!Object



16
17
18
19
20
21
22
23
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/validations/format.rb', line 16

def check_validity!
  unless options.include?(:with) ^ options.include?(:without)  # ^ == xor, or "exclusive or"
    raise ArgumentError, "Either :with or :without must be supplied (but not both)"
  end

  check_options_validity :with
  check_options_validity :without
end

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/activemodel-7.0.4/lib/active_model/validations/format.rb', line 6

def validate_each(record, attribute, value)
  if options[:with]
    regexp = option_call(record, :with)
    record_error(record, attribute, :with, value) unless regexp.match?(value.to_s)
  elsif options[:without]
    regexp = option_call(record, :without)
    record_error(record, attribute, :without, value) if regexp.match?(value.to_s)
  end
end