Class: ActiveStorageValidations::ProcessableImageValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ActiveStorageValidations::ProcessableImageValidator
- Includes:
- ErrorHandler, OptionProcUnfolding
- Defined in:
- lib/active_storage_validations/processable_image_validator.rb
Overview
:nodoc
Instance Method Summary collapse
Methods included from ErrorHandler
#add_error, #initialize_error_options
Methods included from OptionProcUnfolding
Instance Method Details
#validate_each(record, attribute, _value) ⇒ Object
Rails 5
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/active_storage_validations/processable_image_validator.rb', line 27 def validate_each(record, attribute, _value) return true unless record.send(attribute).attached? = () changes = record.[attribute.to_s] return true if changes.blank? files = Array.wrap(changes.is_a?(ActiveStorage::Attached::Changes::CreateMany) ? changes.attachables : changes.attachable) files.each do |file| add_error(record, attribute, :image_not_processable, **) unless Metadata.new(file).valid? end end |