Class: ActiveStorageValidations::BaseComparisonValidator

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

Overview

:nodoc:

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) ⇒ BaseComparisonValidator

Returns a new instance of BaseComparisonValidator.



23
24
25
26
27
28
# File 'lib/active_storage_validations/base_comparison_validator.rb', line 23

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

Instance Method Details

#check_validity!Object



30
31
32
33
34
# File 'lib/active_storage_validations/base_comparison_validator.rb', line 30

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