Class: ActiveStorageValidations::BaseSizeValidator

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

Overview

:nodoc:

Direct Known Subclasses

SizeValidator, TotalSizeValidator

Constant Summary collapse

AVAILABLE_CHECKS =
%i[
  less_than
  less_than_or_equal_to
  greater_than
  greater_than_or_equal_to
  between
].freeze

Instance Method Summary collapse

Methods included from ASVErrorable

#add_error, #initialize_error_options

Constructor Details

#initialize(*args) ⇒ BaseSizeValidator

Returns a new instance of BaseSizeValidator.



25
26
27
28
29
30
# File 'lib/active_storage_validations/base_size_validator.rb', line 25

def initialize(*args)
  if self.class == BaseSizeValidator
    raise NotImplementedError, 'BaseSizeValidator is an abstract class and cannot be instantiated directly.'
  end
  super
end

Instance Method Details

#check_validity!Object



32
33
34
35
36
# File 'lib/active_storage_validations/base_size_validator.rb', line 32

def check_validity!
  unless AVAILABLE_CHECKS.one? { |argument| options.key?(argument) }
    raise ArgumentError, 'You must pass either :less_than(_or_equal_to), :greater_than(_or_equal_to), or :between to the validator'
  end
end