gems dry-types 1.2.0

latest releases: 1.8.2, 1.8.1, 1.8.0...
5 years ago

1.2.0 2019-10-06

Changed

  • Dry::Types.[] used to work with classes, now it's deprecated (flash-gordon)

Fixed

  • Bug with using a Bool-named struct as a schema key (flash-gordon)
  • A bunch of issues related to using meta on complex types (flash-gordon)
  • Types.Constructor(...) returns a Types::Array as it should (flash-gordon)

Added

  • Optional::Params types that coerce empty strings to nil (flash-gordon)

    Dry::Types['optional.params.integer'].('') # => nil
    Dry::Types['optional.params.integer'].('140') # => 140
    Dry::Types['optional.params.integer'].('asd') # => exception!

    Keep in mind, Dry::Types['optional.params.integer'] and Dry::Types['params.integer'].optional are not the same, the latter doesn't handle empty strings.

  • Predicate inferrer was ported from dry-schema (authored by solnic)

    require 'dry/types/predicate_inferrer'
    Dry::Types::PredicateInferrer.new[Types::String]
    # => [:str?]
    Dry::Types::PredicateInferrer.new[Types::String | Types::Integer]
    # => [[[:str?], [:int?]]]

    Note that the API of the predicate inferrer can change in the stable version, it's dictated by the needs of dry-schema so it should be considered as semi-stable. If you depend on it, write specs covering the desired behavior. Another option is copy-and-paste the whole thing to your project.

  • Primitive inferrer was ported from dry-schema (authored by solnic)

    require 'dry/types/primitive_inferrer'
    Dry::Types::PrimitiveInferrer.new[Types::String]
    # => [String]
    Dry::Types::PrimitiveInferrer.new[Types::String | Types::Integer]
    # => [String, Integer]
    Dry::Types::PrimitiveInferrer.new[Types::String.optional]
    # => [NilClass, String]

    The primitive inferrer should be stable by now, you can rely on it.

  • The monads extension adds Dry::Types::Result#to_monad. This makes it compatible with do notation from dry-monads. Load it with Dry::Types.load_extensions(:monads) (skryukov)

    Types = Dry.Types
    Dry::Types.load_extensions(:monads)
    
    class AddTen
      include Dry::Monads[:result, :do]
    
      def call(input)
        integer = yield Types::Coercible::Integer.try(input)
    
        Success(integer + 10)
      end
    end

Compare v1.1.1...v1.2.0

Don't miss a new dry-types release

NewReleases is sending notifications on new releases.