Class: Castkit::Validators::FloatValidator

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

Overview

Validator for Float attributes.

Ensures the value is a ‘Float`, and applies any numeric bounds (`min`, `max`) defined in the attribute options. Inherits shared logic from `NumericValidator`.

Examples:

validator = Castkit::Validators::FloatValidator.new
validator.call(3.14, options: { min: 0.0 }, context: :price) # => passes
validator.call(42, options: {}, context: :price)             # raises Castkit::AttributeError

Instance Method Summary collapse

Methods inherited from Base

call

Instance Method Details

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

This method returns an undefined value.

Validates that the value is a Float and within optional bounds.

Parameters:

  • value (Object, nil)

    the value to validate

  • options (Hash)

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

  • context (Symbol, String)

    the attribute name or key for error messages

Raises:



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

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

  super
end