Class: EnvValidator::Types::Boolean
- Defined in:
- lib/env_validator/types.rb
Constant Summary collapse
- TRUTHY_VALUES =
%w[true 1 yes y on].freeze
- FALSY_VALUES =
%w[false 0 no n off].freeze
- VALID_VALUES =
(TRUTHY_VALUES + FALSY_VALUES).freeze
Instance Method Summary collapse
Instance Method Details
#coerce(value) ⇒ Object
67 68 69 70 |
# File 'lib/env_validator/types.rb', line 67 def coerce(value) normalized = value.to_s.downcase.strip TRUTHY_VALUES.include?(normalized) end |
#validate(value) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/env_validator/types.rb', line 60 def validate(value) normalized = value.to_s.downcase.strip return true if VALID_VALUES.include?(normalized) raise TypeError, "Expected boolean (#{VALID_VALUES.join(", ")}), got #{value.inspect}" end |