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

Version Path
metasploit-model-5.0.2 app/validators/nil_validator.rb
metasploit-model-5.0.1 app/validators/nil_validator.rb
metasploit-model-5.0.0 app/validators/nil_validator.rb
metasploit-model-4.0.6 app/validators/nil_validator.rb
metasploit-model-4.0.5 app/validators/nil_validator.rb
metasploit-model-4.0.4 app/validators/nil_validator.rb
metasploit-model-4.0.3 app/validators/nil_validator.rb
metasploit-model-4.0.2 app/validators/nil_validator.rb
metasploit-model-4.0.1 app/validators/nil_validator.rb
metasploit-model-4.0.0 app/validators/nil_validator.rb
metasploit-model-3.1.4 app/validators/nil_validator.rb
metasploit-model-3.1.3 app/validators/nil_validator.rb
metasploit-model-3.1.2 app/validators/nil_validator.rb
metasploit-model-3.1.1 app/validators/nil_validator.rb
metasploit-model-3.1.0 app/validators/nil_validator.rb