Class: ActiveStorageValidations::AttachedValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
ErrorHandler, Symbolizable
Defined in:
lib/active_storage_validations/attached_validator.rb

Overview

:nodoc:

Constant Summary collapse

ERROR_TYPES =
%i[blank].freeze

Instance Method Summary collapse

Methods included from ErrorHandler

#add_error, #initialize_error_options

Instance Method Details

#validate_each(record, attribute, _value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/active_storage_validations/attached_validator.rb', line 12

def validate_each(record, attribute, _value)
  return if record.send(attribute).attached?

  errors_options = initialize_error_options(options)

  add_error(record, attribute, ERROR_TYPES.first, **errors_options)
end