Class: ActiveStorageValidations::SizeValidator
- Inherits:
-
BaseSizeValidator
- Object
- ActiveModel::EachValidator
- BaseSizeValidator
- ActiveStorageValidations::SizeValidator
- Defined in:
- lib/active_storage_validations/size_validator.rb
Constant Summary collapse
- ERROR_TYPES =
%i[ file_size_not_less_than file_size_not_less_than_or_equal_to file_size_not_greater_than file_size_not_greater_than_or_equal_to file_size_not_between ].freeze
Constants inherited from BaseSizeValidator
BaseSizeValidator::AVAILABLE_CHECKS
Instance Method Summary collapse
Methods inherited from BaseSizeValidator
Methods included from ASVErrorable
#add_error, #initialize_error_options
Constructor Details
This class inherits a constructor from ActiveStorageValidations::BaseSizeValidator
Instance Method Details
#validate_each(record, attribute, _value) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/active_storage_validations/size_validator.rb', line 15 def validate_each(record, attribute, _value) return if (record, attribute) = (record) attached_files(record, attribute).each do |file| next if is_valid?(file.blob.byte_size, ) = (, file) (, ) [:file_size] = number_to_human_size(file.blob.byte_size) keys = AVAILABLE_CHECKS & .keys error_type = "file_size_not_#{keys.first}".to_sym add_error(record, attribute, error_type, **) end end |