Sha256: 6f3a8e87f95b2714d46a37c171157efc163fafd4557d20a6b8e52298adc6a09a
Contents?: true
Size: 718 Bytes
Versions: 15
Compression:
Stored size: 718 Bytes
Contents
# Validator to ensure an attribute is `nil`. Intended for use conditionally with `:if` or `:unless` to ensure an # attribute is `nil` under one condition while a different validation, such as `:presence` or `:inclusion` is used under # the dual of that condition. class NilValidator < ActiveModel::EachValidator # Validates that `value` is `nil`. # # @param record [#errors, ApplicationRecord] an ActiveModel or ActiveRecord # @param attribute [Symbol] name of attribute being validated. # @param value [#nil?] value of `attribute` to check with `nil?` # @return [void] def validate_each(record, attribute, value) unless value.nil? record.errors.add attribute, 'must be nil' end end end
Version data entries
15 entries across 15 versions & 1 rubygems