Class: Castkit::Validator Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/castkit/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`.

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:



19
20
21
# File 'lib/castkit/validator.rb', line 19

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



33
34
35
# File 'lib/castkit/validator.rb', line 33

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