Class: Castkit::Types::Boolean
- 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
-
#deserialize(value) ⇒ Boolean
Deserializes the input into a boolean value.
-
#serialize(value) ⇒ Boolean
Serializes the boolean value (pass-through).
-
#validate!(value, options: {}, context: {}) ⇒ void
Validates the Boolean value.
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`
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).
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.
42 43 44 |
# File 'lib/castkit/types/boolean.rb', line 42 def validate!(value, options: {}, context: {}) Castkit::Validators::BooleanValidator.call(value, options: , context: context) end |