Class: ActiveStorageValidations::AttachedValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ActiveStorageValidations::AttachedValidator
- Includes:
- Errorable, 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 Errorable
#add_error, #initialize_error_options
Instance Method Details
#check_validity! ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/active_storage_validations/attached_validator.rb', line 13 def check_validity! %i(allow_nil allow_blank).each do || if .include?() raise ArgumentError, "You cannot pass the :#{} option to this validator" end end end |
#validate_each(record, attribute, _value) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/active_storage_validations/attached_validator.rb', line 21 def validate_each(record, attribute, _value) return if record.send(attribute).attached? && !Array.wrap(record.send(attribute)).all? { |file| file.marked_for_destruction? } = () add_error(record, attribute, ERROR_TYPES.first, **) end |