Class: ActiveStorageValidations::AspectRatioValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- ActiveStorageValidations::AspectRatioValidator
- Includes:
- ErrorHandler, OptionProcUnfolding
- Defined in:
- lib/active_storage_validations/aspect_ratio_validator.rb
Overview
:nodoc
Constant Summary collapse
- AVAILABLE_CHECKS =
%i[with].freeze
- PRECISION =
3
Instance Method Summary collapse
Methods included from ErrorHandler
#add_error, #initialize_error_options
Methods included from OptionProcUnfolding
Instance Method Details
#check_validity! ⇒ Object
13 14 15 16 17 |
# File 'lib/active_storage_validations/aspect_ratio_validator.rb', line 13 def check_validity! unless AVAILABLE_CHECKS.any? { |argument| .key?(argument) } raise ArgumentError, 'You must pass :with to the validator' end end |
#validate_each(record, attribute, _value) ⇒ Object
Rails 5
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_storage_validations/aspect_ratio_validator.rb', line 36 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| = Metadata.new(file). next if is_valid?(record, attribute, ) break end end |