Class: ActiveStorageValidations::BaseSizeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
Errorable, OptionProcUnfolding, Symbolizable
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 Errorable

#add_error, #initialize_error_options

Methods included from OptionProcUnfolding

#unfold_procs

Constructor Details

#initialize(*args) ⇒ BaseSizeValidator

Returns a new instance of BaseSizeValidator.



22
23
24
25
26
27
# File 'lib/active_storage_validations/base_size_validator.rb', line 22

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



29
30
31
32
33
# File 'lib/active_storage_validations/base_size_validator.rb', line 29

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