Sha256: c65c25e75e0f99c12239ca0776502dfb30b5cd43a0529d133c203cebebbf9575

Contents?: true

Size: 738 Bytes

Versions: 11

Compression:

Stored size: 738 Bytes

Contents

# typed: strict

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

      Target = type_member { {fixed: Integer} }

      sig { override.params(type: T::Types::Base).returns(T::Boolean) }
      def used_for_type?(type)
        type == T::Utils.coerce(Integer)
      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 Integer.")) unless used_for_type?(type)

        Success.new(Integer(value))
      rescue ArgumentError, TypeError
        Failure.new(CoercionError.new("'#{value}' cannot be coerced into Integer."))
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sorbet-schema-0.9.2 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.9.1 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.9.0 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.8.0 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.7.2 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.7.1 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.7.0 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.6.0 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.5.1 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.4.2 lib/typed/coercion/integer_coercer.rb
sorbet-schema-0.4.1 lib/typed/coercion/integer_coercer.rb