Class: ActiveStorageValidations::DimensionValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
ASVActiveStorageable, ASVAnalyzable, ASVAttachable, ASVErrorable, ASVOptionable, ASVSymbolizable
Defined in:
lib/active_storage_validations/dimension_validator.rb

Overview

:nodoc

Constant Summary collapse

AVAILABLE_CHECKS =
%i[width height min max].freeze
ERROR_TYPES =
%i[
  dimension_min_not_included_in
  dimension_max_not_included_in
  dimension_width_not_included_in
  dimension_height_not_included_in
  dimension_width_not_greater_than_or_equal_to
  dimension_height_not_greater_than_or_equal_to
  dimension_width_not_less_than_or_equal_to
  dimension_height_not_less_than_or_equal_to
  dimension_width_not_equal_to
  dimension_height_not_equal_to
  media_metadata_missing
].freeze
METADATA_KEYS =
%i[width height].freeze

Constants included from ASVAnalyzable

ASVAnalyzable::DEFAULT_IMAGE_PROCESSOR

Instance Method Summary collapse

Methods included from ASVErrorable

#add_error, #initialize_error_options

Instance Method Details

#check_validity!Object



35
36
37
38
39
# File 'lib/active_storage_validations/dimension_validator.rb', line 35

def check_validity!
  ensure_at_least_one_validator_option
  ensure_dimension_in_option_validity
  ensure_min_max_option_validity
end

#validate_each(record, attribute, _value) ⇒ Object



41
42
43
44
45
# File 'lib/active_storage_validations/dimension_validator.rb', line 41

def validate_each(record, attribute, _value)
  return if no_attachments?(record, attribute)

  (record, attribute, METADATA_KEYS)
end