Parent

Class/Module Index [+]

Quicksearch

ActiveModel::Validations::FormatValidator

Public Instance Methods

check_validity!() click to toggle source
# File lib/active_model/validations/format.rb, line 14
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

  if options[:with] && !options[:with].is_a?(Regexp)
    raise ArgumentError, "A regular expression must be supplied as the :with option of the configuration hash"
  end

  if options[:without] && !options[:without].is_a?(Regexp)
    raise ArgumentError, "A regular expression must be supplied as the :without option of the configuration hash"
  end
end
validate_each(record, attribute, value) click to toggle source
# File lib/active_model/validations/format.rb, line 6
def validate_each(record, attribute, value)
  if options[:with] && value.to_s !~ options[:with]
    record.errors.add(attribute, :invalid, options.except(:with).merge!(:value => value))
  elsif options[:without] && value.to_s =~ options[:without]
    record.errors.add(attribute, :invalid, options.except(:without).merge!(:value => value))
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.