Class: Castkit::Validators::BaseValidator Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/castkit/validators/base_validator.rb

Overview

This class is abstract.

Abstract base class for all attribute validators.

Validators ensure that a value conforms to specific rules (e.g., type, format, range). Subclasses must implement the instance method ‘#call`.

Direct Known Subclasses

NumericValidator, StringValidator

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

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

This method returns an undefined value.

Invokes the validator with the given arguments.

Parameters:

  • value (Object)

    the attribute value to validate

  • options (Hash)

    the attribute options (e.g., ‘min`, `max`, `format`)

  • context (Symbol, String, Hash)

    the attribute name or context for error reporting

Raises:



20
21
22
# File 'lib/castkit/validators/base_validator.rb', line 20

def call(value, options:, context:)
  new.call(value, options: options, context: context)
end

Instance Method Details

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

This method is abstract.

Override in subclasses.

This method returns an undefined value.

Validates the attribute value.

Parameters:

  • value (Object)

    the attribute value to validate

  • options (Hash)

    the attribute options

  • context (Symbol, String, Hash)

    the attribute name or context

Raises:

  • (NotImplementedError)

    unless implemented in a subclass



34
35
36
# File 'lib/castkit/validators/base_validator.rb', line 34

def call(value, options:, context:)
  raise NotImplementedError, "#{self.class.name} must implement `#call`"
end