dry-types 1.9.0 released

Added

  • params.* with .optional can now handle empty strings consistently with optional.params.* by returning nil instead of raising an error. (@baweaver in #487, @flash-gordon in #490)

    This behavior is not enabled by default because it’s a breaking change. Set Dry::Types.use_namespaced_optionals(true) to enable it.

    Dry::Types["params.integer"].optional.("") # => CoercionError
    # Activate namespaced optionals
    Dry::Types.use_namespaced_optionals true
    Dry::Types["params.integer"].optional.("") # => nil
    

Changed

  • Require Ruby 3.2 or later.
  • Support bigdecimal version 4.0 as well as 3.0, improving compatibility with other gems that require 4.0 only. (@rus-max in #492)
  • Improve sum type error handling documentation. (@baweaver in #486)

Fixed

  • Fix Constructor#primitive? delegation for sum types. (@baweaver in #484)

    This now works without error:

    a = Types::String.constrained(size: 2) | Types::Hash
    b = Types::String.constrained(size: 1) | Types::Hash
    
    c = (a.constructor { |x| x.is_a?(Hash) ? x : x.downcase }) |
        (b.constructor { |x| x.is_a?(Hash) ? x : x.upcase })
    
  • Fix Sum type to_s with Dry::Struct types. (@baweaver in #485)

    This now works without error:

    class A < Dry::Struct; end
    class B < Dry::Struct; end
    
    (A | B).to_s
    

Compare v1.8.3 … v1.9.0


View release on GitHub

1 Like