Sha256: b39e9106b97c7eea71db78b5fccca7c20403ff4c6971d93dc68075dc6a1a7f3a

Contents?: true

Size: 610 Bytes

Versions: 11

Compression:

Stored size: 610 Bytes

Contents

# typed: strict

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

      Target = type_member { {fixed: String} }

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

        Success.new(String(value))
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

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