Changelog History
Page 1
-
v1.6.1 Changes
October 15, 2022๐ Changed
- ๐ Fix issues with internal const_missing and Inflector/Module constants (@flash-gordon + @solnic)
-
v1.6.0 Changes
October 15, 2022๐ Changed
- โก๏ธ Optimize
PredicateRegistry
for Ruby 2.7+ (see #420 for more details) (@casperisfine) - ๐ Use zeitwerk for auto-loading (@flash-gordon)
- โก๏ธ Optimize
-
v1.5.1 Changes
February 16, 2021๐ Fixed
- โ Add missing requires for internal usage of
Dry::Equalizer
(@timriley in #418)
- โ Add missing requires for internal usage of
-
v1.5.0 Changes
January 21, 2021โ Added
- Wrapping constructor types :tada: (@flash-gordon)
Constructor blocks can have a second argument. The second argument is the underlying type itself:
age_from_year = Dry::Types['coercible.integer'].constructor do |input, type| Date.today.year - type.(input) end age_from_year.('2000') # => 21
With wrapping constructors you have control over "type application". You can even run it more than once:
inc = Dry::Types['integer'].constructor(&:succ) inc2x = inc.constructor { _2.(_2.(_2.(_1))) } inc2x.(10) # => 13
- Fallbacks :tada: (@flash-gordon)
age = Dry::Types['coercible.ineger'].fallback(18) age.('10') # => 10 age.('20') # => 20 age.('abc') # => 18
Fallbacks are different from default values: the later will be evaluated only when no input provided.
Under the hood,
.fallback
creates a wrapping constructor.params.string
as an alias forstrict.string
. This addition should be non-breaking (@flash-gordon)- ๐ API for defining custom type builders similar to
.default
,.constructor
, or.optional
(@flash-gordon)
# Making an alias for `.fallback` Dry::Types.define_builder(:or) { |type, v| type.fallback(v) } # Using new builder type = Dry::Types['integer'].or(-273) type.(:invalid) # => -273
๐ Changed
- ๐ Inferring predicates from class names is deprecated. It's very unlikely your code depends on it, however, if it does, you'll get an exception with instructions. (@flash-gordon)
If you don't rely on inferring, just disable it with:
Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name false
Otherwise, enable it explicitly:
Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name true
-
v1.4.0 Changes
March 09, 20201.4.0 2020-03-09
๐ Fixed
json.nil
no longer coerces empty strings tonil
. It was a long-standing
๐ bug that for some reason remained unnoticed for years. Technically,
this may be a breaking change for JSON schemas described with dry-schema (@flash-gordon)
-
v1.3.1 Changes
February 17, 20201.3.1 2020-02-17
๐ Changed
- Predicate inferrer now returns
hash?
for hash schemas. Note, it doesn't spit more complex preds because we have different plans for dry-schema (@flash-gordon)
- Predicate inferrer now returns
-
v1.3.0 Changes
February 10, 2020โ Added
- ๐
Schema#merge
for merging two hash schemas (@waiting-for-dev) Aliases for
.constructor
to non-constructor types. Now you can call.prepend
/.append
without silly checks for the type being a constructor (flash-gordon)(Dry::Types['integer'].prepend(-> { _1 + 1 })).(1) # => 2(Dry::Types['coercible.integer'] >> -> { _1 * 2 }).('99') # => 198
Hash::Schema#clear
returns a schema with the same options but without keys0๏ธโฃ Optional namespace now includes strict types by default (@flash-gordon)
๐ Fixed
Schema::Key#optional
returns an instance ofSchema::Key
as it should have done- Composition with function handling exceptions. This could occasionally lead to unexpected exceptions (@flash-gordon)
- ๐
-
v1.2.2 Changes
December 14, 20191.2.2 2019-12-14
๐ Fixed
- ๐
Types.Contructor
doesn't re-wrap class instances implementing type interface, this fixes some quirks in dry-struct (flash-gordon)
๐ Changed
- ๐ Types now use immutable equalizers. This should improve performance in certain cases e.g. in ROM (flash-gordon)
- Attempting to use non-symbol keys in hash schemas raises an error. We always supported only symbols as keys, but there was no check, now it'll throw an argument error. If you want to convert strings to symbols, use
Hash#with_key_transform
(flash-gordon) - ๐ Params and JSON types accept Time/Date/Datetime instances and boolean values. This can be useful in tests, but we discourage you from relying on this behavior in production code. For example, building structs with
Params
types is considered a smell. There are dedicated tools for coercion, namely dry-schema and dry-validation. Be a responsible user of dry-types! โค (flash-gordon)
- ๐
-
v1.2.1 Changes
November 07, 20191.2.1 2019-11-07
๐ Fixed
- ๐ Fix keyword warnings reported by Ruby 2.7 (flash-gordon)
- Error type in failing case in
Array::Member
(esparta)
-
v1.2.0 Changes
October 06, 2019โ Added
Optional::Params
types that coerce empty strings tonil
(flash-gordon)ruby 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']
andDry::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)
ruby 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)
ruby 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
๐ 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)
๐ Changed
- ๐
Dry::Types.[]
used to work with classes, now it's deprecated (flash-gordon)