Class: Castkit::Validators::IntegerValidator

Inherits:
NumericValidator show all
Defined in:
lib/castkit/validators/integer_validator.rb

Overview

Validator for Integer attributes.

Ensures the value is an instance of ‘Integer` and optionally checks numerical constraints such as `min` and `max`, inherited from `Castkit::Validators::NumericValidator`.

Examples:

Validating an Integer attribute

IntegerValidator.call(42, options: { min: 10, max: 100 }, context: :count)

See Also:

Instance Method Summary collapse

Methods inherited from Base

call

Instance Method Details

#call(value, options:, context:) ⇒ void

This method returns an undefined value.

Validates the Integer value.

Parameters:

  • value (Object, nil)

    the value to validate

  • options (Hash)

    validation options (e.g., ‘min`, `max`)

  • context (Symbol, String)

    the attribute name or context for error messages

Raises:



24
25
26
27
28
# File 'lib/castkit/validators/integer_validator.rb', line 24

def call(value, options:, context:)
  return type_error!(:integer, value, context: context) unless value.is_a?(::Integer)

  super
end