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
  equal_to
].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.



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

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



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

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), :between or :equal_to to the validator"
  end
end

#validate_each(record, attribute, value) ⇒ Object

Raises:

  • (NotImplementedError)


37
38
39
# File 'lib/active_storage_validations/base_comparison_validator.rb', line 37

def validate_each(record, attribute, value)
  raise NotImplementedError
end