Unclaimed project
Are you a maintainer of dry-types? Claim this project to take control of your public changelog and roadmap.
Changelog
Flexible type system for Ruby with coercions and constraints
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
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