Sha256: e961da8dc3810f88a2add4f182c910b76d195eb8c473a184f0548c2ca8637f63
Contents?: true
Size: 843 Bytes
Versions: 11
Compression:
Stored size: 843 Bytes
Contents
# typed: strict module Typed module Coercion class BooleanCoercer < Coercer extend T::Generic Target = type_member { {fixed: T::Boolean} } sig { override.params(type: T::Types::Base).returns(T::Boolean) } def used_for_type?(type) type == T::Utils.coerce(T::Boolean) end sig { override.params(type: T::Types::Base, value: Value).returns(Result[Target, CoercionError]) } def coerce(type:, value:) return Failure.new(CoercionError.new("Type must be a T::Boolean.")) unless used_for_type?(type) if type.recursively_valid?(value) Success.new(value) elsif value == "true" Success.new(true) elsif value == "false" Success.new(false) else Failure.new(CoercionError.new) end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems