Sha256: 229f1822a48a47b93120365a1aae253111e7cd1cf3861fd4e647078ae1269db9
Contents?: true
Size: 618 Bytes
Versions: 4
Compression:
Stored size: 618 Bytes
Contents
# typed: strict module Typed module Coercion class IntegerCoercer < Coercer extend T::Generic Target = type_member { {fixed: Integer} } sig { override.params(type: T::Class[T.anything]).returns(T::Boolean) } def used_for_type?(type) type == Integer end sig { override.params(field: Field, value: Value).returns(Result[Target, CoercionError]) } def coerce(field:, value:) Success.new(Integer(value)) rescue ArgumentError, TypeError Failure.new(CoercionError.new("'#{value}' cannot be coerced into Integer.")) end end end end
Version data entries
4 entries across 4 versions & 1 rubygems