Sha256: c43f8d731cee2851b876daf76625a79a98434afce4a9a6e0e80129d15b22e712

Contents?: true

Size: 637 Bytes

Versions: 1

Compression:

Stored size: 637 Bytes

Contents

# typed: strict

module Typed
  module Coercion
    class FloatCoercer < Coercer
      extend T::Generic

      Target = type_member { {fixed: Float} }

      sig { override.params(type: Field::Type).returns(T::Boolean) }
      def used_for_type?(type)
        T::Utils.coerce(type) == T::Utils.coerce(Float)
      end

      sig { override.params(type: Field::Type, value: Value).returns(Result[Target, CoercionError]) }
      def coerce(type:, value:)
        Success.new(Float(value))
      rescue ArgumentError, TypeError
        Failure.new(CoercionError.new("'#{value}' cannot be coerced into Float."))
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sorbet-schema-0.4.0 lib/typed/coercion/float_coercer.rb