Class: ActiveStorageValidations::AspectRatioValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ActiveStorageValidations::AspectRatioValidator
- Includes:
- ASVActiveStorageable, ASVAnalyzable, ASVAttachable, ASVErrorable, ASVOptionable, ASVSymbolizable
- Defined in:
- lib/active_storage_validations/aspect_ratio_validator.rb
Overview
:nodoc
Constant Summary collapse
- AVAILABLE_CHECKS =
%i[with in].freeze
- NAMED_ASPECT_RATIOS =
%i[square portrait landscape].freeze
- ASPECT_RATIO_REGEX =
/is_([1-9]\d*)_([1-9]\d*)/.freeze
- ERROR_TYPES =
%i[ aspect_ratio_not_square aspect_ratio_not_portrait aspect_ratio_not_landscape aspect_ratio_is_not aspect_ratio_invalid image_metadata_missing ].freeze
- PRECISION =
3.freeze
Constants included from ASVAnalyzable
ActiveStorageValidations::ASVAnalyzable::DEFAULT_IMAGE_PROCESSOR
Instance Method Summary collapse
Methods included from ASVErrorable
#add_error, #initialize_error_options
Instance Method Details
#check_validity! ⇒ Object
32 33 34 35 |
# File 'lib/active_storage_validations/aspect_ratio_validator.rb', line 32 def check_validity! ensure_at_least_one_validator_option ensure_aspect_ratio_validity end |
#validate_each(record, attribute, _value) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/active_storage_validations/aspect_ratio_validator.rb', line 37 def validate_each(record, attribute, _value) return if (record, attribute) = (record) @authorized_aspect_ratios = ().compact return if @authorized_aspect_ratios.empty? (record, attribute) end |