Class: Castkit::Validators::BooleanValidator
- Defined in:
- lib/castkit/validators/boolean_validator.rb
Overview
Validator for boolean attributes.
Accepts various representations of boolean values, including strings and integers. Converts common truthy/falsy string values into booleans, otherwise raises a type error.
This validator is typically used internally by ‘Castkit::Types::Boolean`.
Instance Method Summary collapse
-
#call(value, options:, context:) ⇒ Boolean
Validates the Boolean value.
Methods inherited from Base
Instance Method Details
#call(value, options:, context:) ⇒ Boolean
Validates the Boolean value.
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/castkit/validators/boolean_validator.rb', line 27 def call(value, options:, context:) # rubocop:disable Lint/UnusedMethodArgument case value.to_s.downcase when "true", "1" true when "false", "0" false else type_error!(:boolean, value, context: context) end end |