Class: Castkit::Types::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/castkit/types/boolean.rb

Overview

Type definition for ‘:boolean` attributes.

Converts strings or numbers into boolean values based on common truthy/falsy indicators.

This class is used internally by Castkit when an attribute is defined with:

`boolean :is_active`

Instance Method Summary collapse

Methods inherited from Base

cast!, deserialize, serialize, validate!

Instance Method Details

#deserialize(value) ⇒ Boolean

Deserializes the input into a boolean value.

Accepts:

  • ‘“true”`, `“1”` (case-insensitive) → `true`

  • ‘“false”`, `“0”` (case-insensitive) → `false`

Parameters:

  • value (Object)

Returns:

Raises:



24
25
26
# File 'lib/castkit/types/boolean.rb', line 24

def deserialize(value)
  value
end

#serialize(value) ⇒ Boolean

Serializes the boolean value (pass-through).

Parameters:

Returns:



32
33
34
# File 'lib/castkit/types/boolean.rb', line 32

def serialize(value)
  value
end

#validate!(value, options: {}, context: {}) ⇒ void

This method returns an undefined value.

Validates the Boolean value.

Parameters:

  • value (Object)
  • options (Hash) (defaults to: {})

    validation options

  • context (Symbol, String) (defaults to: {})

    attribute context for error messages



42
43
44
# File 'lib/castkit/types/boolean.rb', line 42

def validate!(value, options: {}, context: {})
  Castkit::Validators::BooleanValidator.call(value, options: options, context: context)
end