Module: Candid::Internal::Types::Boolean
- Extended by:
- Union
- Defined in:
- lib/candid/internal/types/boolean.rb
Class Method Summary collapse
-
.coerce(value, strict: strict?) ) ⇒ Object
Overrides the base coercion method for enums to allow integer and string values to become booleans.
Methods included from Union
coerce, discriminant, member, member?, members
Methods included from Type
Methods included from JSON::Serializable
Class Method Details
.coerce(value, strict: strict?) ) ⇒ Object
Overrides the base coercion method for enums to allow integer and string values to become booleans
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/candid/internal/types/boolean.rb', line 17 def self.coerce(value, strict: strict?) case value when TrueClass, FalseClass value when Integer return value == 1 when String return %w[1 true].include?(value) end raise Errors::TypeError, "cannot coerce `#{value.class}` to Boolean" if strict value end |