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 aTypes::Array
as it should (flash-gordon)
Added
-
Optional::Params
types that coerce empty strings tonil
(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 addsDry::Types::Result#to_monad
. This makes it compatible with do notation from dry-monads. Load it withDry::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