dry-types 0.13.2 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +763 -233
  3. data/LICENSE +17 -17
  4. data/README.md +15 -13
  5. data/dry-types.gemspec +28 -28
  6. data/lib/dry-types.rb +3 -1
  7. data/lib/dry/types.rb +156 -76
  8. data/lib/dry/types/any.rb +32 -12
  9. data/lib/dry/types/array.rb +19 -6
  10. data/lib/dry/types/array/constructor.rb +32 -0
  11. data/lib/dry/types/array/member.rb +75 -16
  12. data/lib/dry/types/builder.rb +131 -15
  13. data/lib/dry/types/builder_methods.rb +49 -20
  14. data/lib/dry/types/coercions.rb +76 -22
  15. data/lib/dry/types/coercions/json.rb +43 -7
  16. data/lib/dry/types/coercions/params.rb +118 -31
  17. data/lib/dry/types/compat.rb +0 -2
  18. data/lib/dry/types/compiler.rb +56 -41
  19. data/lib/dry/types/constrained.rb +81 -32
  20. data/lib/dry/types/constrained/coercible.rb +36 -6
  21. data/lib/dry/types/constraints.rb +18 -4
  22. data/lib/dry/types/constructor.rb +127 -54
  23. data/lib/dry/types/constructor/function.rb +216 -0
  24. data/lib/dry/types/constructor/wrapper.rb +94 -0
  25. data/lib/dry/types/container.rb +7 -0
  26. data/lib/dry/types/core.rb +54 -21
  27. data/lib/dry/types/decorator.rb +38 -17
  28. data/lib/dry/types/default.rb +61 -16
  29. data/lib/dry/types/enum.rb +43 -20
  30. data/lib/dry/types/errors.rb +75 -9
  31. data/lib/dry/types/extensions.rb +7 -1
  32. data/lib/dry/types/extensions/maybe.rb +74 -16
  33. data/lib/dry/types/extensions/monads.rb +29 -0
  34. data/lib/dry/types/fn_container.rb +6 -1
  35. data/lib/dry/types/hash.rb +86 -67
  36. data/lib/dry/types/hash/constructor.rb +33 -0
  37. data/lib/dry/types/inflector.rb +3 -1
  38. data/lib/dry/types/json.rb +18 -16
  39. data/lib/dry/types/lax.rb +75 -0
  40. data/lib/dry/types/map.rb +76 -33
  41. data/lib/dry/types/meta.rb +51 -0
  42. data/lib/dry/types/module.rb +120 -0
  43. data/lib/dry/types/nominal.rb +210 -0
  44. data/lib/dry/types/options.rb +13 -26
  45. data/lib/dry/types/params.rb +39 -25
  46. data/lib/dry/types/predicate_inferrer.rb +238 -0
  47. data/lib/dry/types/predicate_registry.rb +34 -0
  48. data/lib/dry/types/primitive_inferrer.rb +97 -0
  49. data/lib/dry/types/printable.rb +16 -0
  50. data/lib/dry/types/printer.rb +315 -0
  51. data/lib/dry/types/result.rb +29 -3
  52. data/lib/dry/types/schema.rb +408 -0
  53. data/lib/dry/types/schema/key.rb +156 -0
  54. data/lib/dry/types/spec/types.rb +103 -33
  55. data/lib/dry/types/sum.rb +84 -35
  56. data/lib/dry/types/type.rb +49 -0
  57. data/lib/dry/types/version.rb +3 -1
  58. metadata +68 -79
  59. data/.gitignore +0 -10
  60. data/.rspec +0 -2
  61. data/.travis.yml +0 -29
  62. data/.yardopts +0 -5
  63. data/CONTRIBUTING.md +0 -29
  64. data/Gemfile +0 -24
  65. data/Rakefile +0 -20
  66. data/benchmarks/hash_schemas.rb +0 -51
  67. data/lib/dry/types/compat/form_types.rb +0 -27
  68. data/lib/dry/types/compat/int.rb +0 -14
  69. data/lib/dry/types/definition.rb +0 -113
  70. data/lib/dry/types/hash/schema.rb +0 -199
  71. data/lib/dry/types/hash/schema_builder.rb +0 -75
  72. data/lib/dry/types/safe.rb +0 -59
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d7399dfa5c9458f87055807c64d0fcb7be54517c171a3cf198c485fb7ce3ef5c
4
- data.tar.gz: 9e47f234bbd30a8883977c524bde4211704a04d7680d332061c5825aa600de98
3
+ metadata.gz: 7c7c872991cdfc4269f8de895e51cd19b129f6ef86fb78b48ff5ca5bb1e811d8
4
+ data.tar.gz: b3600454a14b4dde65512f8c55f4c2a9ec1e9293d45364cde763bb0e1185fa9b
5
5
  SHA512:
6
- metadata.gz: ebb5e60b9b7ade7ca10f49616b2a985beda12e43ced6477af470ad7d8dfb7b60846e0553fbff4b0c54b6f3eb589ae6feb9b445f5fdc357272fe08a2ba7852baf
7
- data.tar.gz: cf7520decd6f3df3d90837adc14bfcefb2544fd7ea53b6f315a2c0f90cc67f5808a6d8a79e9ce8332a7f7e62591f69010bfa1a58241db1fab445f38780534e70
6
+ metadata.gz: 5f0286b20cd4c40478587e083ff4ef7fb6bb39e66ee01864c7f5710697f30378742899ae509181be215096cf76b26d2c1aa14e4b1f2bd651058911e201d5281f
7
+ data.tar.gz: 2a1ae064396c3074bf28d90fe94867b62b2c787ea0798a7f934bc81b2232b46616f7ee71ad7caaa4612712f1ff306f9f255969b0e4ad67f28e12925fd77dd658
data/CHANGELOG.md CHANGED
@@ -1,55 +1,533 @@
1
- # v0.13.2 2018-05-30
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
2
 
3
- ## Fixed
3
+ ## 1.5.1 2021-02-16
4
4
 
5
- * `Defaults#valid?` now works fine when passing `Dry::Core::Constans::Undefined` as value (GustavoCaso)
6
- * `valid?` for constructor types wrapping `Sum`s (GustavoCaso)
7
5
 
8
- [Compare v0.13.1...v0.13.2](https://github.com/dry-rb/dry-types/compare/v0.13.1...v0.13.2)
6
+ ### Fixed
9
7
 
10
- # v0.13.1 2018-05-28
8
+ - Add missing requires for internal usage of `Dry::Equalizer` (@timriley in #418)
11
9
 
12
- ## Fixed
13
10
 
14
- * Defaults now works fine with meta (GustavoCaso)
15
- * Defaults are now re-decorated properly (flash-gordon)
11
+ [Compare v1.5.0...v1.5.1](https://github.com/dry-rb/dry-types/compare/v1.5.0...v1.5.1)
16
12
 
17
- ## Added
13
+ ## 1.5.0 2021-01-21
18
14
 
19
- * `params.int` was added to make the upgrade process in dry-validation smoother (available after you `require 'dry/types/compat/int'`) (flash-gordon)
20
15
 
21
- [Compare v0.13.0...v0.13.1](https://github.com/dry-rb/dry-types/compare/v0.13.0...v0.13.1)
16
+ ### Added
22
17
 
23
- # v0.13.0 2018-05-03
18
+ - Wrapping constructor types :tada: (@flash-gordon)
24
19
 
25
- ## Changed
20
+ Constructor blocks can have a second argument.
21
+ The second argument is the underlying type itself:
22
+ ```ruby
23
+ age_from_year = Dry::Types['coercible.integer'].constructor do |input, type|
24
+ Date.today.year - type.(input)
25
+ end
26
+ age_from_year.('2000') # => 21
27
+ ```
28
+ With wrapping constructors you have control over "type application". You can even
29
+ run it more than once:
30
+ ```ruby
31
+ inc = Dry::Types['integer'].constructor(&:succ)
32
+ inc2x = inc.constructor { _2.(_2.(_2.(_1))) }
33
+ inc2x.(10) # => 13
34
+ ```
35
+ - Fallbacks :tada: (@flash-gordon)
26
36
 
27
- * [BREAKING] Renamed `Types::Form` to `Types::Params`. You can opt-in the former name with `require 'dry/types/compat/form_types'`. It will be dropped in the next release (ndrluis)
28
- * [BREAKING] The `Int` types was renamed to `Integer`, this was the only type named differently from the standard Ruby classes so it has been made consistent. The former name is available with `require 'dry/types/compat/int'` (GustavoCaso + flash-gordon)
29
- * [BREAKING] Default types are not evaluated on `nil`. Default values are evaluated _only_ if no value were given.
30
37
  ```ruby
31
- type = Types::Strict::String.default("hello")
32
- type[nil] # => constraint error
33
- type[] # => "hello"
38
+ age = Dry::Types['coercible.ineger'].fallback(18)
39
+ age.('10') # => 10
40
+ age.('20') # => 20
41
+ age.('abc') # => 18
34
42
  ```
35
- This change allowed to greatly simplify hash schemas, make them a lot more flexible yet predictable (see below).
36
- * [BREAKING] `Dry::Types.register_class` was removed, `Dry::Types.register` was made private API, do not register your types in the global `dry-types` container, use a module instead, e.g. `Types` (flash-gordon)
37
- * [BREAKING] Enum types don't accept value index anymore. Instead, explicit mapping is supported, see below (flash-gordon)
38
43
 
44
+ Fallbacks are different from default values: the later will be evaluated
45
+ only when *no input* provided.
46
+
47
+ Under the hood, `.fallback` creates a wrapping constructor.
48
+ - `params.string` as an alias for `strict.string`. This addition should be non-breaking (@flash-gordon)
49
+ - API for defining custom type builders similar to `.default`, `.constructor`, or `.optional` (@flash-gordon)
50
+
51
+ ```ruby
52
+ # Making an alias for `.fallback`
53
+ Dry::Types.define_builder(:or) { |type, v| type.fallback(v) }
54
+
55
+ # Using new builder
56
+ type = Dry::Types['integer'].or(-273)
57
+ type.(:invalid) # => -273
58
+ ```
59
+
60
+ ### Changed
61
+
62
+ - Inferring predicates from class names is deprecated. It's very unlikely your code depends on it,
63
+ however, if it does, you'll get an exception with instructions. (@flash-gordon)
64
+
65
+ If you don't rely on inferring, just disable it with:
66
+
67
+ ```ruby
68
+ Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name false
69
+ ```
70
+
71
+ Otherwise, enable it explicitly:
72
+
73
+ ```ruby
74
+ Dry::Types::PredicateInferrer::Compiler.infer_predicate_by_class_name true
75
+ ```
76
+
77
+ [Compare v1.4.0...v1.5.0](https://github.com/dry-rb/dry-types/compare/v1.4.0...v1.5.0)
78
+
79
+ ## 1.4.0 2020-03-09
80
+
81
+
82
+ ### Fixed
83
+
84
+ - `json.nil` no longer coerces empty strings to `nil`. It was a long-standing
85
+ bug that for some reason remained unnoticed for years. Technically,
86
+ this may be a breaking change for JSON schemas described with dry-schema (@flash-gordon)
87
+
88
+
89
+ [Compare v1.3.1...v1.4.0](https://github.com/dry-rb/dry-types/compare/v1.3.1...v1.4.0)
90
+
91
+ ## 1.3.1 2020-02-17
92
+
93
+
94
+ ### Changed
95
+
96
+ - 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)
97
+
98
+ [Compare v1.3.0...v1.3.1](https://github.com/dry-rb/dry-types/compare/v1.3.0...v1.3.1)
99
+
100
+ ## 1.3.0 2020-02-10
101
+
102
+
103
+ ### Added
104
+
105
+ - `Schema#merge` for merging two hash schemas (@waiting-for-dev)
106
+ - Aliases for `.constructor` to non-constructor types. Now you can call `.prepend`/`.append` without silly checks for the type being a constructor (flash-gordon)
107
+ ```ruby
108
+ (Dry::Types['integer'].prepend(-> { _1 + 1 })).(1) # => 2
109
+ (Dry::Types['coercible.integer'] >> -> { _1 * 2 }).('99') # => 198
110
+ ```
111
+ - `Hash::Schema#clear` returns a schema with the same options but without keys
112
+ - Optional namespace now includes strict types by default (@flash-gordon)
113
+
114
+ ### Fixed
115
+
116
+ - `Schema::Key#optional` returns an instance of `Schema::Key` as it should have done
117
+ - Composition with function handling exceptions. This could occasionally lead to unexpected exceptions (@flash-gordon)
118
+
119
+
120
+ [Compare v1.2.2...v1.3.0](https://github.com/dry-rb/dry-types/compare/v1.2.2...v1.3.0)
121
+
122
+ ## 1.2.2 2019-12-14
123
+
124
+
125
+ ### Fixed
126
+
127
+ - `Types.Contructor` doesn't re-wrap class instances implementing type interface, this fixes some quirks in dry-struct (@flash-gordon)
128
+
129
+ ### Changed
130
+
131
+ - Types now use immutable equalizers. This should improve performance in certain cases e.g. in ROM (flash-gordon)
132
+ - 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)
133
+ - 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 responsible user of dry-types! ❤ (flash-gordon)
134
+
135
+ [Compare v1.2.1...v1.2.2](https://github.com/dry-rb/dry-types/compare/v1.2.1...v1.2.2)
136
+
137
+ ## 1.2.1 2019-11-07
138
+
139
+
140
+ ### Fixed
141
+
142
+ - Fix keyword warnings reported by Ruby 2.7 (flash-gordon)
143
+ - Error type in failing case in `Array::Member` (esparta)
144
+
145
+
146
+ [Compare v1.2.0...v1.2.1](https://github.com/dry-rb/dry-types/compare/v1.2.0...v1.2.1)
147
+
148
+ ## 1.2.0 2019-10-06
149
+
150
+
151
+ ### Added
152
+
153
+ - `Optional::Params` types that coerce empty strings to `nil` (flash-gordon)
154
+ ```ruby
155
+ Dry::Types['optional.params.integer'].('') # => nil
156
+ Dry::Types['optional.params.integer'].('140') # => 140
157
+ Dry::Types['optional.params.integer'].('asd') # => exception!
158
+ ```
159
+ 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.
160
+ - Predicate inferrer was ported from dry-schema (authored by solnic)
161
+ ```ruby
162
+ require 'dry/types/predicate_inferrer'
163
+ Dry::Types::PredicateInferrer.new[Types::String]
164
+ # => [:str?]
165
+ Dry::Types::PredicateInferrer.new[Types::String | Types::Integer]
166
+ # => [[[:str?], [:int?]]]
167
+ ```
168
+ 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.
169
+ - Primitive inferrer was ported from dry-schema (authored by solnic)
170
+ ```ruby
171
+ require 'dry/types/primitive_inferrer'
172
+ Dry::Types::PrimitiveInferrer.new[Types::String]
173
+ # => [String]
174
+ Dry::Types::PrimitiveInferrer.new[Types::String | Types::Integer]
175
+ # => [String, Integer]
176
+ Dry::Types::PrimitiveInferrer.new[Types::String.optional]
177
+ # => [NilClass, String]
178
+ ```
179
+ The primitive inferrer should be stable by now, you can rely on it.
180
+ - 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)
181
+
182
+ ```ruby
183
+ Types = Dry.Types
184
+ Dry::Types.load_extensions(:monads)
185
+
186
+ class AddTen
187
+ include Dry::Monads[:result, :do]
188
+
189
+ def call(input)
190
+ integer = yield Types::Coercible::Integer.try(input)
191
+
192
+ Success(integer + 10)
193
+ end
194
+ end
195
+ ```
196
+
197
+ ### Fixed
198
+
199
+ - Bug with using a `Bool`-named struct as a schema key (flash-gordon)
200
+ - A bunch of issues related to using `meta` on complex types (flash-gordon)
201
+ - `Types.Constructor(...)` returns a `Types::Array` as it should (flash-gordon)
202
+
203
+ ### Changed
204
+
205
+ - `Dry::Types.[]` used to work with classes, now it's deprecated (flash-gordon)
206
+
207
+ [Compare v1.1.1...v1.2.0](https://github.com/dry-rb/dry-types/compare/v1.1.1...v1.2.0)
208
+
209
+ ## 1.1.1 2019-07-26
210
+
211
+
212
+ ### Fixed
213
+
214
+ - A bug where meta was lost for lax array types (flash-gordon)
215
+
216
+
217
+ [Compare v1.1.0...v1.1.1](https://github.com/dry-rb/dry-types/compare/v1.1.0...v1.1.1)
218
+
219
+ ## 1.1.0 2019-07-02
220
+
221
+
222
+ ### Added
223
+
224
+ - New builder method `Interface` constructs a type which accepts objects that respond to the given methods (waiting-for-dev)
225
+ ```ruby
226
+ Types = Dry.Types()
227
+ Types::Callable = Types.Interface(:call)
228
+ Types::Callable.valid?(Object.new) # => false
229
+ Types::Callable.valid?(proc {}) # => true
230
+ ```
231
+ - New types: `coercible.symbol`, `params.symbol`, and `json.symbol`, all use `.to_sym` for coercion (waiting-for-dev)
232
+
233
+ ### Fixed
234
+
235
+ - Converting schema keys to maybe types (flash-gordon)
236
+ - Using `Schema#key` and `Array#member` on constuctors (flash-gordon)
237
+ - Using `meta(omittable: true)` within `transform_types` works again but produces a warning, please migrate to `.omittable` or `.required(false)` (flash-gordon)
238
+ - Bug with a constructror defined on top of enum (flash-gordon)
239
+
240
+
241
+ [Compare v1.0.1...v1.1.0](https://github.com/dry-rb/dry-types/compare/v1.0.1...v1.1.0)
242
+
243
+ ## 1.0.1 2019-06-04
244
+
245
+
246
+ ### Added
247
+
248
+ - In a case of failure the constructor block can now pass a different value (flash-gordon)
249
+ ```ruby
250
+ not_empty_string = Types::String.constructor do |value, &failure|
251
+ value.strip.empty? ? failure.(nil) : value.strip
252
+ end
253
+ not_empty_string.(' ') { |v| v } # => nil
254
+ not_empty_string.lax.(' ') # => nil
255
+ not_empty_string.lax.(' foo ') # => "foo"
256
+ ```
257
+ - `Schema#strict` now accepts an boolean argument. If `fales` is passed this will turn a strict schema into a non-strict one (flash-gordon)
258
+
259
+
260
+ [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-types/compare/v1.0.0...v1.0.1)
261
+
262
+ ## 1.0.0 2019-04-23
263
+
264
+
265
+ ### Added
266
+
267
+ - API for custom constructor types was enhanced. If you pass your own callable to `.constructor` it can have a block in its signature. If a block is passed, you must call it on failed coercion, otherwise raise a type coercion error (flash-gordon)
268
+ Example:
269
+ ```ruby
270
+ proc do |input, &block|
271
+ if input.is_a? String
272
+ Integer(input, 10)
273
+ else
274
+ Integer(input)
275
+ end
276
+ rescue ArgumentError, TypeError => error
277
+ if block
278
+ block.call
279
+ else
280
+ raise Dry::Types::CoercionError.new(
281
+ error.message,
282
+ backtrace: error.backtrace
283
+ )
284
+ end
285
+ end
286
+ ```
287
+ This makes the exception handling your job so that dry-types won't have to catch and re-wrap all possible errors (this is not safe, generally speaking).
288
+ - Types now can be converted to procs thus you can pass them as blocks (flash-gordon)
289
+ ```ruby
290
+ %w(1 2 3).map(&Types::Coercible::Integer)
291
+ # => [1, 2, 3]
292
+ ```
293
+
294
+ ### Changed
295
+
296
+ - [BREAKING] Behavior of built-in constructor types was changed to be more strict. They will always raise an error on failed coercion (flash-gordon)
297
+ Compare:
298
+
299
+ ```ruby
300
+ # 0.15.0
301
+ Types::Params::Integer.('foo')
302
+ # => "foo"
303
+
304
+ # 1.0.0
305
+ Types::Params::Integer.('foo')
306
+ # => Dry::Types::CoercionError: invalid value for Integer(): "foo"
307
+ ```
308
+
309
+ To handle coercion errors `Type#call` now yields a block:
310
+
311
+ ```ruby
312
+ Types::Params::Integer.('foo') { :invalid } # => :invalid
313
+ ```
314
+
315
+ This makes work with coercions more straightforward and way faster.
316
+ - [BREAKING] Safe types were renamed to Lax, this name better serves their purpose. The previous name is available but prints a warning (flash-gordon)
317
+ - [BREAKING] Metadata is now pushed down to the decorated type. It is not likely you will notice a difference but this a breaking change that enables some use cases in rom related to the usage of default types in relations (flash-gordon)
318
+ - Nominal types are now completely unconstrained. This fixes some inconsistencies when using them with constraints. `Nominal#try` will always return a successful result, for the previous behavior use `Nominal#try_coerce` or switch to strict types with passing a block to `#call` (flash-gordon)
319
+ - ## Performance improvements
320
+ - During the work on this release, a lot of performance improvements were made. dry-types 1.0 combined with dry-logic 1.0 are multiple times faster than dry-types 0.15 and dry-logic 0.5 for common cases including constraints checking and coercion (flash-gordon)
321
+
322
+ [Compare v0.15.0...v1.0.0](https://github.com/dry-rb/dry-types/compare/v0.15.0...v1.0.0)
323
+
324
+ ## 0.15.0 2019-03-22
325
+
326
+
327
+ ### Added
328
+
329
+ - Improved string representation of types (flash-gordon)
330
+ ```ruby
331
+ Dry::Types['nominal.integer']
332
+ # => #<Dry::Types[Nominal<Integer>]>
333
+ Dry::Types['params.integer']
334
+ # => #<Dry::Types[Constructor<Nominal<Integer> fn=Dry::Types::Coercions::Params.to_int>]>
335
+ Dry::Types['hash'].schema(age?: 'integer')
336
+ # => #<Dry::Types[Constrained<Schema<keys={age?: Constrained<Nominal<Integer> rule=[type?(Integer)]>}> rule=[type?(Hash)]>]>
337
+ Dry::Types['array<integer>']
338
+ # => #<Dry::Types[Constrained<Array<Constrained<Nominal<Integer> rule=[type?(Integer)]>> rule=[type?(Array)]>]>
339
+ ```
340
+ - Options for the list of types you want to import with `Dry.Types` (flash-gordon)
341
+ Cherry-pick only certain types:
342
+ ```ruby
343
+ module Types
344
+ include Dry.Types(:strict, :nominal, :coercible)
345
+ end
346
+ Types.constants
347
+ # => [:Strict, :Nominal, :Coercible]
348
+ ```
349
+ Change default top-level types:
350
+ ```ruby
351
+ module Types
352
+ include Dry.Types(default: :coercible)
353
+ end
354
+ # => #<Dry::Types[Constructor<Nominal<Integer> fn=Kernel.Integer>]>
355
+ ```
356
+ Rename type namespaces:
357
+ ```ruby
358
+ module Types
359
+ include Dry.Types(strict: :Strong, coercible: :Kernel)
360
+ end
361
+ ```
362
+ - Optional keys for schemas can be provided with ?-ending symbols (flash-gordon)
363
+ ```ruby
364
+ Dry::Types['hash'].schema(name: 'string', age?: 'integer')
365
+ ```
366
+ - Another way of making keys optional is setting `required: false` to meta. In fact, it is the preferable
367
+ way if you have to store this information in `meta`, otherwise use the Key's API (see below) (flash-gordon)
368
+ ```ruby
369
+ Dry::Types['hash'].schema(
370
+ name: Dry::Types['string'],
371
+ age: Dry::Types['integer'].meta(required: false)
372
+ )
373
+ ```
374
+ - Key types have API for making keys omittable and back (flash-gordon)
375
+
376
+ ```ruby
377
+ # defining a base schema with optional keys
378
+ lax_hash = Dry::Types['hash'].with_type_transform { |key| key.required(false) }
379
+ # same as
380
+ lax_hash = Dry::Types['hash'].with_type_transform(&:omittable)
381
+
382
+ # keys in user_schema are not required
383
+ user_schema = lax_hash.schema(name: 'string', age: 'integer')
384
+ ```
385
+ - `Type#optional?` now recognizes more cases where `nil` is an allowed value (flash-gordon)
386
+ - `Constructor#{prepend,append}` with `<<` and `>>` as aliases. `Constructor#append` works the same way `Constructor#constrcutor` does. `Constuctor#prepend` chains functions in the reverse order, see examples (flash-gordon)
387
+
388
+ ```ruby
389
+ to_int = Types::Coercible::Integer
390
+ inc = to_int.append { |x| x + 2 }
391
+ inc.("1") # => "1" -> 1 -> 3
392
+
393
+ inc = to_int.prepend { |x| x + "2" }
394
+ inc.("1") # => "1" -> "12" -> 12
395
+ ```
396
+ - Partial schema application for cases when you want to validate only a subset of keys (flash-gordon)
397
+ This is useful when you want to update a key or two in an already-validated hash. A perfect example is `Dry::Struct#new` where this feature is now used.
398
+ ```ruby
399
+ schema = Dry::Types['hash'].schema(name: 'string', age: 'integer')
400
+ value = schema.(name: 'John', age: 20)
401
+ update = schema.apply({ age: 21 }, skip_missing: true)
402
+ value.merge(update)
403
+ ```
404
+
405
+ ### Fixed
406
+
407
+ - `Hash::Map` now behaves as a constrained type if its values are constrained (flash-gordon)
408
+ - `coercible.integer` now doesn't blow up on invalid strings (exterm)
409
+
410
+ ### Changed
411
+
412
+ - [BREAKING] Internal representation of hash schemas was changed to be a simple list of key types (flash-gordon)
413
+ `Dry::Types::Hash#with_type_transform` now yields a key type instead of type + name:
414
+ ```ruby
415
+ Dry::Types['strict.hash'].with_type_transform { |key| key.name == :age ? key.required(false) : key }
416
+ ```
417
+ - [BREAKING] Definition types were renamed to nominal (flash-gordon)
418
+ - [BREAKING] Top-level types returned by `Dry::Types.[]` are now strict (flash-gordon)
419
+ ```ruby
420
+ # before
421
+ Dry::Types['integer']
422
+ # => #<Dry::Types[Nominal<Integer>]>
423
+ # now
424
+ Dry::Types['integer']
425
+ # => <Dry::Types[Constrained<Nominal<Integer> rule=[type?(Integer)]>]>
426
+ # you can still access nominal types using namespace
427
+ Dry::Types['nominal.integer']
428
+ # => #<Dry::Types[Nominal<Integer>]>
429
+ ```
430
+ - [BREAKING] Default values are not evaluated if the decorated type returns `nil`. They are triggered on `Undefined` instead (GustavoCaso + flash-gordon)
431
+ - [BREAKING] Support for old hash schemas was fully removed. This makes dry-types not compatible with dry-validation < 1.0 (flash-gordon)
432
+ - `Dry::Types.module` is deprecated in favor of `Dry.Types` (flash-gordon)
433
+ Keep in mind `Dry.Types` uses strict types for top-level names, that is after
434
+ ```ruby
435
+ module Types
436
+ include Dry.Types
437
+ end
438
+ ```
439
+ `Types::Integer` is a strict type. If you want it to be nominal, use `include Dry.Types(default: :nominal)`. See other options below.
440
+ - `params.integer` now always converts strings to decimal numbers, this means `09` will be coerced to `9` (threw an error before) (skryukov)
441
+ - Ruby 2.3 is EOL and not officially supported. It may work but we don't test it.
442
+
443
+ [Compare v0.14.1...v0.15.0](https://github.com/dry-rb/dry-types/compare/v0.14.1...v0.15.0)
444
+
445
+ ## 0.14.1 2019-03-25
446
+
447
+
448
+ ### Fixed
449
+
450
+ - `coercible.integer` now doesn't blow up on invalid strings (exterm)
451
+
452
+
453
+ [Compare v0.14.0...v0.14.1](https://github.com/dry-rb/dry-types/compare/v0.14.0...v0.14.1)
454
+
455
+ ## 0.14.0 2019-01-29
456
+
457
+
458
+ ### Fixed
459
+
460
+ - `valid?` works correctly with constructors now (cgeorgii)
461
+
462
+ ### Changed
463
+
464
+ - [BREAKING] Support for Ruby 2.2 was dropped. It reached EOL on March 31, 2018.
465
+ - `dry-logic` was updated to `~> 0.5` (solnic)
466
+
467
+ [Compare v0.13.4...v0.14.0](https://github.com/dry-rb/dry-types/compare/v0.13.4...v0.14.0)
468
+
469
+ ## 0.13.4 2018-12-21
470
+
471
+
472
+ ### Fixed
473
+
474
+ - Fixed warnings about keyword arguments from Ruby 2.6. See https://bugs.ruby-lang.org/issues/14183 for all the details (flash-gordon)
475
+
476
+
477
+ [Compare v0.13.3...v0.13.4](https://github.com/dry-rb/dry-types/compare/v0.13.3...v0.13.4)
478
+
479
+ ## 0.13.3 2018-11-25
480
+
481
+
482
+ ### Fixed
483
+
484
+ - `Dry::Types::Hash#try` returns `Failure` instead of throwing an exception on missing keys (GustavoCaso)
485
+
486
+
487
+ [Compare v0.13.2...v0.13.3](https://github.com/dry-rb/dry-types/compare/v0.13.2...v0.13.3)
488
+
489
+ ## 0.13.2 2018-05-30
490
+
491
+
492
+ ### Fixed
493
+
494
+ - `Defaults#valid?` now works fine when passing `Dry::Core::Constans::Undefined` as value (GustavoCaso)
495
+ - `valid?` for constructor types wrapping `Sum`s (GustavoCaso)
39
496
 
40
- ## Added
41
497
 
42
- * Hash schemas were rewritten. The old API is still around but is going to be deprecated and removed before 1.0. The new API is simpler and more flexible. Instead of having a bunch of predefined schemas you can build your own by combining the following methods:
498
+ [Compare v0.13.1...v0.13.2](https://github.com/dry-rb/dry-types/compare/v0.13.1...v0.13.2)
499
+
500
+ ## 0.13.1 2018-05-28
501
+
502
+
503
+ ### Added
504
+
505
+ - `params.int` was added to make the upgrade process in dry-validation smoother (available after you `require 'dry/types/compat/int'`) (flash-gordon)
506
+
507
+ ### Fixed
508
+
509
+ - Defaults now works fine with meta (GustavoCaso)
510
+ - Defaults are now re-decorated properly (flash-gordon)
511
+
512
+
513
+ [Compare v0.13.0...v0.13.1](https://github.com/dry-rb/dry-types/compare/v0.13.0...v0.13.1)
514
+
515
+ ## 0.13.0 2018-05-03
516
+
517
+
518
+ ### Added
519
+
520
+ - Hash schemas were rewritten. The old API is still around but is going to be deprecated and removed before 1.0. The new API is simpler and more flexible. Instead of having a bunch of predefined schemas you can build your own by combining the following methods:
43
521
 
44
522
  1. `Schema#with_key_transform`—transforms keys of input hashes, for things like symbolizing etc.
45
523
  2. `Schema#strict`—makes a schema intolerant to unknown keys.
46
524
  3. `Hash#with_type_transform`—transforms member types with an arbitrary block. For instance,
47
525
 
48
- ```ruby
49
- optional_keys = Types::Hash.with_type_transform { |t, _key| t.optional }
50
- schema = optional_keys.schema(name: 'strict.string', age: 'strict.int')
51
- schema.(name: "Jane", age: nil) # => {name: "Jane", age: nil}
52
- ```
526
+ ```ruby
527
+ optional_keys = Types::Hash.with_type_transform { |t, _key| t.optional }
528
+ schema = optional_keys.schema(name: 'strict.string', age: 'strict.int')
529
+ schema.(name: "Jane", age: nil) # => {name: "Jane", age: nil}
530
+ ```
53
531
 
54
532
  Note that by default all keys are required, if a key is expected to be absent, add to the corresponding type's meta `omittable: true`:
55
533
 
@@ -75,15 +553,14 @@
75
553
  ```
76
554
 
77
555
  (flash-gordon)
78
-
79
- * `Types.Strict` is an alias for `Types.Instance` (flash-gordon)
556
+ - `Types.Strict` is an alias for `Types.Instance` (flash-gordon)
80
557
  ```ruby
81
558
  strict_range = Types.Strict(Range)
82
559
  strict_range == Types.Instance(Range) # => true
83
560
  ```
84
- * `Enum#include?` is an alias to `Enum#valid?` (d-Pixie + flash-gordon)
85
- * `Range` was added (GustavoCaso)
86
- * `Array` types filter out `Undefined` values, if you have an array type with a constructor type as its member, the constructor now can return `Dry::Types::Undefined` to indicate empty value:
561
+ - `Enum#include?` is an alias to `Enum#valid?` (d-Pixie + flash-gordon)
562
+ - `Range` was added (GustavoCaso)
563
+ - `Array` types filter out `Undefined` values, if you have an array type with a constructor type as its member, the constructor now can return `Dry::Types::Undefined` to indicate empty value:
87
564
  ```ruby
88
565
  filter_empty_strings = Types::Strict::Array.of(
89
566
  Types::Strict::String.constructor { |input|
@@ -92,235 +569,272 @@
92
569
  )
93
570
  filter_empty_strings.(["John", nil, "", "Jane"]) # => ["John", "Jane"]
94
571
  ```
95
- * `Types::Map` was added for homogeneous hashes, when only types of keys and values are known in advance, not specific key names (fledman + flash-gordon)
572
+ - `Types::Map` was added for homogeneous hashes, when only types of keys and values are known in advance, not specific key names (fledman + flash-gordon)
96
573
  ```ruby
97
574
  int_to_string = Types::Hash.map('strict.integer', 'strict.string')
98
575
  int_to_string[0 => 'foo'] # => { 0 => "foo" }
99
576
  int_to_string[0 => 1] # Dry::Types::MapError: input value 1 for key 0 is invalid: type?(String, 1)
100
577
  ```
101
- * Enum supports mappings (bolshakov + flash-gordon)
578
+ - Enum supports mappings (bolshakov + flash-gordon)
102
579
  ```ruby
103
580
  dict = Types::Strict::String.enum('draft' => 0, 'published' => 10, 'archived' => 20)
104
581
  dict['published'] # => 'published'
105
582
  dict[10] # => 'published'
106
583
  ```
107
584
 
108
- ## Fixed
585
+ ### Fixed
109
586
 
110
- * Fixed applying constraints to optional type, i.e. `.optional.constrained` works correctly (flash-gordon)
111
- * Fixed enum working with optionals (flash-gordon)
587
+ - Fixed applying constraints to optional type, i.e. `.optional.constrained` works correctly (flash-gordon)
588
+ - Fixed enum working with optionals (flash-gordon)
589
+ - ## Internal
590
+ - Dropped the `dry-configurable` dependency (GustavoCaso)
591
+ - The gem now uses `dry-inflector` for inflections instead of `inflecto` (GustavoCaso)
112
592
 
113
- ## Internal
593
+ ### Changed
114
594
 
115
- * Dropped the `dry-configurable` dependency (GustavoCaso)
116
- * The gem now uses `dry-inflector` for inflections instead of `inflecto` (GustavoCaso)
595
+ - [BREAKING] Renamed `Types::Form` to `Types::Params`. You can opt-in the former name with `require 'dry/types/compat/form_types'`. It will be dropped in the next release (ndrluis)
596
+ - [BREAKING] The `Int` types was renamed to `Integer`, this was the only type named differently from the standard Ruby classes so it has been made consistent. The former name is available with `require 'dry/types/compat/int'` (GustavoCaso + flash-gordon)
597
+ - [BREAKING] Default types are not evaluated on `nil`. Default values are evaluated _only_ if no value were given.
598
+ ```ruby
599
+ type = Types::Strict::String.default("hello")
600
+ type[nil] # => constraint error
601
+ type[] # => "hello"
602
+ ```
603
+ This change allowed to greatly simplify hash schemas, make them a lot more flexible yet predictable (see below).
604
+ - [BREAKING] `Dry::Types.register_class` was removed, `Dry::Types.register` was made private API, do not register your types in the global `dry-types` container, use a module instead, e.g. `Types` (flash-gordon)
605
+ - [BREAKING] Enum types don't accept value index anymore. Instead, explicit mapping is supported, see below (flash-gordon)
117
606
 
118
607
  [Compare v0.12.2...v0.13.0](https://github.com/dry-rb/dry-types/compare/v0.12.2...v0.13.0)
119
608
 
120
- # v0.12.2 2017-11-04
609
+ ## 0.12.2 2017-11-04
610
+
121
611
 
122
- ## Fixed
612
+ ### Fixed
613
+
614
+ - The type compiler was fixed for simple rules such as used for strict type checks (flash-gordon)
615
+ - Fixed an error on `Dry::Types['json.decimal'].try(nil)` (nesaulov)
616
+ - Fixed an error on calling `try` on an array type built of constrained types (flash-gordon)
617
+ - Implemented `===` for enum types (GustavoCaso)
123
618
 
124
- * The type compiler was fixed for simple rules such as used for strict type checks (flash-gordon)
125
- * Fixed an error on `Dry::Types['json.decimal'].try(nil)` (nesaulov)
126
- * Fixed an error on calling `try` on an array type built of constrained types (flash-gordon)
127
- * Implemented `===` for enum types (GustavoCaso)
128
619
 
129
620
  [Compare v0.12.1...v0.12.2](https://github.com/dry-rb/dry-types/compare/v0.12.1...v0.12.2)
130
621
 
131
- # v0.12.1 2017-10-11
622
+ ## 0.12.1 2017-10-11
623
+
132
624
 
133
- ## Fixed
625
+ ### Fixed
626
+
627
+ - `Constructor#try` rescues `ArgumentError` (raised in cases like `Integer('foo')`) (flash-gordon)
628
+ - `#constructor` works correctly for default and enum types (solnic)
629
+ - Optional sum types work correctly in `safe` mode (GustavoCaso)
630
+ - The equalizer of constrained types respects meta (flash-gordon)
134
631
 
135
- * `Constructor#try` rescues `ArgumentError` (raised in cases like `Integer('foo')`) (flash-gordon)
136
- * `#constructor` works correctly for default and enum types (solnic)
137
- * Optional sum types work correctly in `safe` mode (GustavoCaso)
138
- * The equalizer of constrained types respects meta (flash-gordon)
139
632
 
140
633
  [Compare v0.12.0...v0.12.1](https://github.com/dry-rb/dry-types/compare/v0.12.0...v0.12.1)
141
634
 
142
- # v0.12.0 2017-09-15
635
+ ## 0.12.0 2017-09-15
143
636
 
144
- ## Added
145
637
 
146
- * A bunch of shortcut methods for constructing types to the autogenerated module, e.g. `Types.Constructor(String, &:to_s)` (flash-gordon)
638
+ ### Added
147
639
 
148
- ## Deprecated
640
+ - A bunch of shortcut methods for constructing types to the autogenerated module, e.g. `Types.Constructor(String, &:to_s)` (flash-gordon)
641
+ - ## Deprecated
642
+ - `Types::Array#member` was deprecated in favor of `Types::Array#of` (flash-gordon)
149
643
 
150
- * `Types::Array#member` was deprecated in favor of `Types::Array#of` (flash-gordon)
151
644
 
152
645
  [Compare v0.11.1...v0.12.0](https://github.com/dry-rb/dry-types/compare/v0.11.1...v0.12.0)
153
646
 
154
- # v0.11.1 2017-08-14
647
+ ## 0.11.1 2017-08-14
648
+
155
649
 
156
- ## Changed
650
+ ### Fixed
157
651
 
158
- * Constructors are now equalized using `fn` and `meta` too (flash-gordon)
652
+ - Fixed `Constructor#name` with `Sum`-types (flash-gordon)
159
653
 
160
- ## Fixed
654
+ ### Changed
161
655
 
162
- * Fixed `Constructor#name` with `Sum`-types (flash-gordon)
656
+ - Constructors are now equalized using `fn` and `meta` too (flash-gordon)
163
657
 
164
658
  [Compare v0.11.0...v0.11.1](https://github.com/dry-rb/dry-types/compare/v0.11.0...v0.11.1)
165
659
 
166
- # v0.11.0 2017-06-30
660
+ ## 0.11.0 2017-06-30
167
661
 
168
- ## Added
169
662
 
170
- * `#to_ast` available for all type objects (GustavoCaso)
171
- * `Types::Array#of` as an alias for `#member` (maliqq)
172
- * Detailed failure objects are passed to results which improves constraint violation messages (GustavoCaso)
663
+ ### Added
664
+
665
+ - `#to_ast` available for all type objects (GustavoCaso)
666
+ - `Types::Array#of` as an alias for `#member` (maliqq)
667
+ - Detailed failure objects are passed to results which improves constraint violation messages (GustavoCaso)
668
+
173
669
 
174
670
  [Compare v0.10.3...v0.11.0](https://github.com/dry-rb/dry-types/compare/v0.10.3...v0.11.0)
175
671
 
176
- # v0.10.3 2017-05-06
672
+ ## 0.10.3 2017-05-06
673
+
674
+
675
+ ### Added
177
676
 
178
- ## Added
677
+ - Callable defaults accept the underlying type (v-kolesnikov)
179
678
 
180
- * Callable defaults accept the underlying type (v-kolesnikov)
181
679
 
182
680
  [Compare v0.10.2...v0.10.3](https://github.com/dry-rb/dry-types/compare/v0.10.2...v0.10.3)
183
681
 
184
- # v0.10.2 2017-04-28
682
+ ## 0.10.2 2017-04-28
185
683
 
186
- ## Fixed
187
684
 
188
- * Fixed `Type#optional?` for sum types (flash-gordon)
685
+ ### Fixed
686
+
687
+ - Fixed `Type#optional?` for sum types (flash-gordon)
688
+
189
689
 
190
690
  [Compare v0.10.1...v0.10.2](https://github.com/dry-rb/dry-types/compare/v0.10.1...v0.10.2)
191
691
 
192
- # v0.10.1 2017-04-28
692
+ ## 0.10.1 2017-04-28
693
+
694
+
695
+ ### Added
193
696
 
194
- ## Added
697
+ - `Type#optional?` returns true if type is Sum and left is nil (GustavoCaso)
698
+ - `Type#pristine` returns a type without `meta` (flash-gordon)
195
699
 
196
- * `Type#optional?` returns true if type is Sum and left is nil (GustavoCaso)
197
- * `Type#pristine` returns a type without `meta` (flash-gordon)
700
+ ### Fixed
198
701
 
199
- ## Fixed
702
+ - `meta` is used in type equality again (solnic)
703
+ - `Any` works correctly with meta again (flash-gordon)
200
704
 
201
- * `meta` is used in type equality again (solnic)
202
- * `Any` works correctly with meta again (flash-gordon)
203
705
 
204
706
  [Compare v0.10.0...v0.10.1](https://github.com/dry-rb/dry-types/compare/v0.10.0...v0.10.1)
205
707
 
206
- # v0.10.0 2017-04-26
708
+ ## 0.10.0 2017-04-26
207
709
 
208
- ## Added
209
710
 
210
- * Types can be used in `case` statements now (GustavoCaso)
711
+ ### Added
211
712
 
212
- ## Fixed
713
+ - Types can be used in `case` statements now (GustavoCaso)
213
714
 
214
- * Return original value when Date.parse raises a RangeError (jviney)
715
+ ### Fixed
215
716
 
216
- ## Changed
717
+ - Return original value when Date.parse raises a RangeError (jviney)
217
718
 
218
- * Meta data are now stored separately from options (flash-gordon)
219
- * `Types::Object` was renamed to `Types::Any` (flash-gordon)
719
+ ### Changed
720
+
721
+ - Meta data are now stored separately from options (flash-gordon)
722
+ - `Types::Object` was renamed to `Types::Any` (flash-gordon)
220
723
 
221
724
  [Compare v0.9.4...v0.10.0](https://github.com/dry-rb/dry-types/compare/v0.9.4...v0.10.0)
222
725
 
223
- # v0.9.4 2017-01-24
726
+ ## 0.9.4 2017-01-24
727
+
224
728
 
225
- ## Added
729
+ ### Added
730
+
731
+ - Added `Types::Object` which passes an object of any type (flash-gordon)
226
732
 
227
- * Added `Types::Object` which passes an object of any type (flash-gordon)
228
733
 
229
734
  [Compare v0.9.3...v0.9.4](https://github.com/dry-rb/dry-types/compare/v0.9.3...v0.9.4)
230
735
 
231
- # v0.9.3 2016-12-03
736
+ ## 0.9.3 2016-12-03
737
+
232
738
 
233
- ## Fixed
739
+ ### Fixed
740
+
741
+ - Updated to dry-core >= 0.2.1 (ruby warnings are gone) (flash-gordon)
234
742
 
235
- * Updated to dry-core >= 0.2.1 (ruby warnings are gone) (flash-gordon)
236
743
 
237
744
  [Compare v0.9.2...v0.9.3](https://github.com/dry-rb/dry-types/compare/v0.9.2...v0.9.3)
238
745
 
239
- # v0.9.2 2016-11-13
746
+ ## 0.9.2 2016-11-13
747
+
240
748
 
241
- ## Added
749
+ ### Added
242
750
 
243
- * Support for `"Y"` and `"N"` as `true` and `false` values, respectively (scare21410)
751
+ - Support for `"Y"` and `"N"` as `true` and `false` values, respectively (scare21410)
244
752
 
245
- ## Changed
753
+ ### Changed
246
754
 
247
- * Optimized object allocation in hash schemas, resulting in up to 25% speed boost (davydovanton)
755
+ - Optimized object allocation in hash schemas, resulting in up to 25% speed boost (davydovanton)
248
756
 
249
757
  [Compare v0.9.1...v0.9.2](https://github.com/dry-rb/dry-types/compare/v0.9.1...v0.9.2)
250
758
 
251
- # v0.9.1 2016-11-04
759
+ ## 0.9.1 2016-11-04
252
760
 
253
- ## Fixed
254
761
 
255
- * `Hash#strict_with_defaults` properly evaluates callable defaults (bolshakov)
762
+ ### Fixed
256
763
 
257
- ## Changed
764
+ - `Hash#strict_with_defaults` properly evaluates callable defaults (bolshakov)
258
765
 
259
- * `Hash#weak` accepts Hash-descendants again (solnic)
766
+ ### Changed
767
+
768
+ - `Hash#weak` accepts Hash-descendants again (solnic)
260
769
 
261
770
  [Compare v0.9.0...v0.9.1](https://github.com/dry-rb/dry-types/compare/v0.9.0...v0.9.1)
262
771
 
263
- # v0.9.0 2016-09-21
772
+ ## 0.9.0 2016-09-21
773
+
264
774
 
265
- ## Added
775
+ ### Added
266
776
 
267
- * `Hash#strict_with_defaults` which validates presence of all required keys and respects default types for missing *values* (backus)
268
- * `Type#constrained?` method (flash-gordon)
777
+ - `Hash#strict_with_defaults` which validates presence of all required keys and respects default types for missing _values_ (backus)
778
+ - `Type#constrained?` method (flash-gordon)
269
779
 
270
- ## Fixed
780
+ ### Fixed
271
781
 
272
- * Summing two constrained types works correctly (flash-gordon)
273
- * `Types::Array::Member#valid?` in cases where member type is a constraint (solnic)
274
- * `Hash::Schema#try` handles exceptions properly and returns a failure object (solnic)
782
+ - Summing two constrained types works correctly (flash-gordon)
783
+ - `Types::Array::Member#valid?` in cases where member type is a constraint (solnic)
784
+ - `Hash::Schema#try` handles exceptions properly and returns a failure object (solnic)
275
785
 
276
- ## Changed
786
+ ### Changed
277
787
 
278
- * [BREAKING] Renamed `Hash##{schema=>permissive}` (backus)
279
- * [BREAKING] `dry-monads` dependency was made optional, Maybe types are available after `Dry::Types.load_extensions(:maybe)` (flash-gordon)
280
- * [BREAKING] `Dry::Types::Struct` and `Dry::Types::Value` have been extracted to [`dry-struct`](https://github.com/dry-rb/dry-struct) (backus)
281
- * `Types::Form::Bool` supports upcased true/false values (kirs)
282
- * `Types::Form::{Date,DateTime,Time}` fail gracefully for invalid input (padde)
283
- * ice_nine dependency has been dropped as it was required by Struct only (flash-gordon)
788
+ - [BREAKING] Renamed `Hash##{schema=>permissive}` (backus)
789
+ - [BREAKING] `dry-monads` dependency was made optional, Maybe types are available after `Dry::Types.load_extensions(:maybe)` (flash-gordon)
790
+ - [BREAKING] `Dry::Types::Struct` and `Dry::Types::Value` have been extracted to [`dry-struct`](https://github.com/dry-rb/dry-struct) (backus)
791
+ - `Types::Form::Bool` supports upcased true/false values (kirs)
792
+ - `Types::Form::{Date,DateTime,Time}` fail gracefully for invalid input (padde)
793
+ - ice_nine dependency has been dropped as it was required by Struct only (flash-gordon)
284
794
 
285
795
  [Compare v0.8.1...v0.9.0](https://github.com/dry-rb/dry-types/compare/v0.8.1...v0.9.0)
286
796
 
287
- # v0.8.1 2016-07-13
797
+ ## 0.8.1 2016-07-13
288
798
 
289
- ## Fixed
290
799
 
291
- * Compiler no longer chokes on type nodes without args (solnic)
292
- * Removed `bin/console` from gem package (solnic)
800
+ ### Fixed
801
+
802
+ - Compiler no longer chokes on type nodes without args (solnic)
803
+ - Removed `bin/console` from gem package (solnic)
804
+
293
805
 
294
806
  [Compare v0.8.0...v0.8.1](https://github.com/dry-rb/dry-types/compare/v0.8.0...v0.8.1)
295
807
 
296
- # v0.8.0 2016-07-01
808
+ ## 0.8.0 2016-07-01
297
809
 
298
- ## Added
299
810
 
300
- * `Struct` now implements `Type` interface so ie `SomeStruct | String` works now (flash-gordon)
301
- * `:weak` Hash constructor which can partially coerce a hash even when it includes invalid values (solnic)
302
- * Types include `Dry::Equalizer` now (flash-gordon)
811
+ ### Added
303
812
 
304
- ## Fixed
813
+ - `Struct` now implements `Type` interface so ie `SomeStruct | String` works now (flash-gordon)
814
+ - `:weak` Hash constructor which can partially coerce a hash even when it includes invalid values (solnic)
815
+ - Types include `Dry::Equalizer` now (flash-gordon)
305
816
 
306
- * `Struct#to_hash` descends into arrays too (nepalez)
307
- * `Default#with` works now (flash-gordon)
817
+ ### Fixed
308
818
 
309
- ## Changed
819
+ - `Struct#to_hash` descends into arrays too (nepalez)
820
+ - `Default#with` works now (flash-gordon)
310
821
 
311
- * `:symbolized` hash schema is now based on `:weak` schema (solnic)
312
- * `Struct::Value` instances are now **deeply frozen** via ice_nine (backus)
822
+ ### Changed
823
+
824
+ - `:symbolized` hash schema is now based on `:weak` schema (solnic)
825
+ - `Struct::Value` instances are now **deeply frozen** via ice_nine (backus)
313
826
 
314
827
  [Compare v0.7.2...v0.8.0](https://github.com/dry-rb/dry-types/compare/v0.7.2...v0.8.0)
315
828
 
316
- # v0.7.2 2016-05-11
829
+ ## 0.7.2 2016-05-11
830
+
317
831
 
318
- ## Fixed
832
+ ### Fixed
319
833
 
320
834
  - `Bool#default` gladly accepts `false` as its value (solnic)
321
835
  - Creating an empty schema with input processor no longer fails (lasseebert)
322
836
 
323
- ## Changed
837
+ ### Changed
324
838
 
325
839
  - Allow multiple calls to meta (solnic)
326
840
  - Allow capitalised versions of true and false values for boolean coercions (nil0bject)
@@ -332,24 +846,26 @@
332
846
 
333
847
  [Compare v0.7.1...v0.7.2](https://github.com/dry-rb/dry-types/compare/v0.7.1...v0.7.2)
334
848
 
335
- # v0.7.1 2016-04-06
849
+ ## 0.7.1 2016-04-06
336
850
 
337
- ## Added
851
+
852
+ ### Added
338
853
 
339
854
  - `JSON::*` types with JSON-specific coercions (coop)
340
855
 
341
- ## Fixed
856
+ ### Fixed
342
857
 
343
858
  - Schema is properly inherited in Struct (backus)
344
859
  - `constructor_type` is properly inherited in Struct (fbernier)
345
860
 
861
+
346
862
  [Compare v0.7.0...v0.7.1](https://github.com/dry-rb/dry-types/compare/v0.7.0...v0.7.1)
347
863
 
348
- # v0.7.0 2016-03-30
864
+ ## 0.7.0 2016-03-30
349
865
 
350
866
  Major focus of this release is to make complex type composition possible and improving constraint errors to be more meaningful.
351
867
 
352
- ## Added
868
+ ### Added
353
869
 
354
870
  - `Type#try` interface that tries to process the input and return a result object which can be either a success or failure (solnic)
355
871
  - `#meta` interface for setting arbitrary meta data on types (solnic)
@@ -359,12 +875,12 @@ Major focus of this release is to make complex type composition possible and imp
359
875
  - Compiler supports `[:constructor, [primitive, fn_proc]]` nodes (solnic)
360
876
  - Compiler supports building schema-less `form.hash` types (solnic)
361
877
 
362
- ## Fixed
878
+ ### Fixed
363
879
 
364
880
  - `Sum` now supports complex types like `Array` or `Hash` with member types and/or constraints (solnic)
365
881
  - `Default#constrained` will properly wrap a new constrained type (solnic)
366
882
 
367
- ## Changed
883
+ ### Changed
368
884
 
369
885
  - [BREAKING] Renamed `Type#{optional=>maybe}` (AMHOL)
370
886
  - [BREAKING] `Type#optional(other)` builds a sum: `Strict::Nil | other` (AMHOL)
@@ -379,172 +895,186 @@ Major focus of this release is to make complex type composition possible and imp
379
895
 
380
896
  [Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-types/compare/v0.6.0...v0.7.0)
381
897
 
382
- # v0.6.0 2016-03-16
898
+ ## 0.6.0 2016-03-16
383
899
 
384
900
  Renamed from `dry-data` to `dry-types` and:
385
901
 
386
- ## Added
902
+ ### Added
387
903
 
388
- * `Dry::Types.module` which returns a namespace for inclusion which has all
904
+ - `Dry::Types.module` which returns a namespace for inclusion which has all
389
905
  built-in types defined as constants (solnic)
390
- * `Hash#schema` supports default values now (solnic)
391
- * `Hash#symbolized` passes through keys that are already symbols (solnic)
392
- * `Struct.new` uses an empty hash by default as input (solnic)
393
- * `Struct.constructor_type` macro can be used to change attributes constructor (solnic)
394
- * `default` accepts a block now for dynamic values (solnic)
395
- * `Types.register_class` accepts a second arg which is the name of the class'
906
+ - `Hash#schema` supports default values now (solnic)
907
+ - `Hash#symbolized` passes through keys that are already symbols (solnic)
908
+ - `Struct.new` uses an empty hash by default as input (solnic)
909
+ - `Struct.constructor_type` macro can be used to change attributes constructor (solnic)
910
+ - `default` accepts a block now for dynamic values (solnic)
911
+ - `Types.register_class` accepts a second arg which is the name of the class'
396
912
  constructor method, defaults to `:new` (solnic)
397
913
 
398
- ## Fixed
914
+ ### Fixed
399
915
 
400
- * `Struct` will simply pass-through the input if it is already a struct (solnic)
401
- * `default` will raise if a value violates constraints (solnic)
402
- * Evaluating a default value tries to use type's constructor which makes it work
916
+ - `Struct` will simply pass-through the input if it is already a struct (solnic)
917
+ - `default` will raise if a value violates constraints (solnic)
918
+ - Evaluating a default value tries to use type's constructor which makes it work
403
919
  with types that may coerce an input into nil (solnic)
404
- * `enum` works just fine with integer-values (solnic)
405
- * `enum` + `default` works just fine (solnic)
406
- * `Optional` no longer responds to `primitive` as it makes no sense since there's
920
+ - `enum` works just fine with integer-values (solnic)
921
+ - `enum` + `default` works just fine (solnic)
922
+ - `Optional` no longer responds to `primitive` as it makes no sense since there's
407
923
  no single primitive for an optional value (solnic)
408
- * `Optional` passes-through a value which is already a maybe (solnic)
924
+ - `Optional` passes-through a value which is already a maybe (solnic)
409
925
 
410
- ## Changed
926
+ ### Changed
411
927
 
412
- * `Dry::Types::Definition` is now the base type definition object (solnic)
413
- * `Dry::Types::Constructor` is now a type definition with a constructor function (solnic)
928
+ - `Dry::Types::Definition` is now the base type definition object (solnic)
929
+ - `Dry::Types::Constructor` is now a type definition with a constructor function (solnic)
414
930
 
415
931
  [Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-types/compare/v0.5.1...v0.6.0)
416
932
 
417
- # v0.5.1 2016-01-11
933
+ ## 0.5.1 2016-01-11
418
934
 
419
- ## Added
420
935
 
421
- * `Dry::Data::Type#safe` for types which can skip constructor when primitive does
936
+ ### Added
937
+
938
+ - `Dry::Data::Type#safe` for types which can skip constructor when primitive does
422
939
  not match input's class (solnic)
423
- * `form.array` and `form.hash` safe types (solnic)
940
+ - `form.array` and `form.hash` safe types (solnic)
941
+
424
942
 
425
943
  [Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-types/compare/v0.5.0...v0.5.1)
426
944
 
427
- # v0.5.0 2016-01-11
945
+ ## 0.5.0 2016-01-11
428
946
 
429
- ## Added
430
947
 
431
- * `Type#default` interface for defining a type with a default value (solnic)
948
+ ### Added
432
949
 
433
- ## Changed
950
+ - `Type#default` interface for defining a type with a default value (solnic)
434
951
 
435
- * [BREAKING] `Dry::Data::Type.new` accepts constructor and *options* now (solnic)
436
- * Renamed `Dry::Data::Type::{Enum,Constrained}` => `Dry::Data::{Enum,Constrained}` (solnic)
437
- * `dry-logic` is now a dependency for constrained types (solnic)
438
- * Constrained types are now always available (solnic)
439
- * `strict.*` category uses constrained types with `:type?` predicate (solnic)
440
- * `SumType#call` no longer needs to rescue from `TypeError` (solnic)
952
+ ### Fixed
441
953
 
442
- ## Fixed
954
+ - `attribute` raises proper error when type definition is missing (solnic)
443
955
 
444
- * `attribute` raises proper error when type definition is missing (solnic)
956
+ ### Changed
957
+
958
+ - [BREAKING] `Dry::Data::Type.new` accepts constructor and _options_ now (solnic)
959
+ - Renamed `Dry::Data::Type::{Enum,Constrained}` => `Dry::Data::{Enum,Constrained}` (solnic)
960
+ - `dry-logic` is now a dependency for constrained types (solnic)
961
+ - Constrained types are now always available (solnic)
962
+ - `strict.*` category uses constrained types with `:type?` predicate (solnic)
963
+ - `SumType#call` no longer needs to rescue from `TypeError` (solnic)
445
964
 
446
965
  [Compare v0.4.2...v0.5.0](https://github.com/dry-rb/dry-types/compare/v0.4.2...v0.5.0)
447
966
 
448
- # v0.4.2 2015-12-27
967
+ ## 0.4.2 2015-12-27
968
+
449
969
 
450
- ## Added
970
+ ### Added
451
971
 
452
- * Support for arrays in type compiler (solnic)
972
+ - Support for arrays in type compiler (solnic)
453
973
 
454
- ## Changed
974
+ ### Changed
455
975
 
456
- * Array member uses type objects now rather than just their constructors (solnic)
976
+ - Array member uses type objects now rather than just their constructors (solnic)
457
977
 
458
- [Compare v0.4.1...v0.4.2](https://github.com/dry-rb/dry-types/compare/v0.4.1...v0.4.2)
978
+ [Compare v0.4.0...v0.4.2](https://github.com/dry-rb/dry-types/compare/v0.4.0...v0.4.2)
459
979
 
460
- # v0.4.0 2015-12-11
980
+ ## 0.4.0 2015-12-11
461
981
 
462
- ## Added
463
982
 
464
- * Support for sum-types with constraint type (solnic)
465
- * `Dry::Data::Type#optional` for defining optional types (solnic)
983
+ ### Added
466
984
 
467
- ## Changed
985
+ - Support for sum-types with constraint type (solnic)
986
+ - `Dry::Data::Type#optional` for defining optional types (solnic)
468
987
 
469
- * `Dry::Data['optional']` was **removed** in favor of `Dry::Data::Type#optional` (solnic)
988
+ ### Changed
989
+
990
+ - `Dry::Data['optional']` was **removed** in favor of `Dry::Data::Type#optional` (solnic)
470
991
 
471
992
  [Compare v0.3.2...v0.4.0](https://github.com/dry-rb/dry-types/compare/v0.3.2...v0.4.0)
472
993
 
473
- # v0.3.2 2015-12-10
994
+ ## 0.3.2 2015-12-10
995
+
474
996
 
475
- ## Added
997
+ ### Added
476
998
 
477
- * `Dry::Data::Value` which works like a struct but is a value object with equalizer (solnic)
999
+ - `Dry::Data::Value` which works like a struct but is a value object with equalizer (solnic)
478
1000
 
479
- ## Fixed
1001
+ ### Fixed
1002
+
1003
+ - Added missing require for `dry-equalizer` (solnic)
480
1004
 
481
- * Added missing require for `dry-equalizer` (solnic)
482
1005
 
483
1006
  [Compare v0.3.1...v0.3.2](https://github.com/dry-rb/dry-types/compare/v0.3.1...v0.3.2)
484
1007
 
485
- # v0.3.1 2015-12-09
1008
+ ## 0.3.1 2015-12-09
1009
+
486
1010
 
487
- ## Changed
1011
+ ### Changed
488
1012
 
489
- * Removed require of constrained type and make it optional (solnic)
1013
+ - Removed require of constrained type and make it optional (solnic)
490
1014
 
491
1015
  [Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-types/compare/v0.3.0...v0.3.1)
492
1016
 
493
- # v0.3.0 2015-12-09
1017
+ ## 0.3.0 2015-12-09
1018
+
1019
+
1020
+ ### Added
494
1021
 
495
- ## Added
1022
+ - `Type#constrained` interface for defining constrained types (solnic)
1023
+ - `Dry::Data` can be configured with a type namespace (solnic)
1024
+ - `Dry::Data.finalize` can be used to define types as constants under configured namespace (solnic)
1025
+ - `Dry::Data::Type#enum` for defining an enum from a specific type (solnic)
1026
+ - New types: `symbol` and `class` along with their `strict` versions (solnic)
496
1027
 
497
- * `Type#constrained` interface for defining constrained types (solnic)
498
- * `Dry::Data` can be configured with a type namespace (solnic)
499
- * `Dry::Data.finalize` can be used to define types as constants under configured namespace (solnic)
500
- * `Dry::Data::Type#enum` for defining an enum from a specific type (solnic)
501
- * New types: `symbol` and `class` along with their `strict` versions (solnic)
502
1028
 
503
1029
  [Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-types/compare/v0.2.1...v0.3.0)
504
1030
 
505
- # v0.2.1 2015-11-30
1031
+ ## 0.2.1 2015-11-30
506
1032
 
507
- ## Added
508
1033
 
509
- * Type compiler supports nested hashes now (solnic)
1034
+ ### Added
510
1035
 
511
- ## Fixed
1036
+ - Type compiler supports nested hashes now (solnic)
512
1037
 
513
- * `form.bool` sum is using correct right-side `form.false` type (solnic)
1038
+ ### Fixed
514
1039
 
515
- ## Changed
1040
+ - `form.bool` sum is using correct right-side `form.false` type (solnic)
516
1041
 
517
- * Improved structure of the ast (solnic)
1042
+ ### Changed
1043
+
1044
+ - Improved structure of the ast (solnic)
518
1045
 
519
1046
  [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-types/compare/v0.2.0...v0.2.1)
520
1047
 
521
- # v0.2.0 2015-11-29
1048
+ ## 0.2.0 2015-11-29
1049
+
522
1050
 
523
- ## Added
1051
+ ### Added
524
1052
 
525
- * `form.nil` which coerces empty strings to `nil` (solnic)
526
- * `bool` sum-type (true | false) (solnic)
527
- * Type compiler supports sum-types now (solnic)
1053
+ - `form.nil` which coerces empty strings to `nil` (solnic)
1054
+ - `bool` sum-type (true | false) (solnic)
1055
+ - Type compiler supports sum-types now (solnic)
528
1056
 
529
- ## Changed
1057
+ ### Changed
530
1058
 
531
- * Constructing optional types uses the new `Dry::Data["optional"]` built-in type (solnic)
1059
+ - Constructing optional types uses the new `Dry::Data["optional"]` built-in type (solnic)
532
1060
 
533
1061
  [Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-types/compare/v0.1.0...v0.2.0)
534
1062
 
535
- # v0.1.0 2015-11-27
1063
+ ## 0.1.0 2015-11-27
536
1064
 
537
- ## Added
538
1065
 
539
- * `form.*` coercible types (solnic)
540
- * `Type::Hash#strict` for defining hashes with a strict schema (solnic)
541
- * `Type::Hash#symbolized` for defining hashes that will symbolize keys (solnic)
542
- * `Dry::Data.register_class` short-cut interface for registering a class and
1066
+ ### Added
1067
+
1068
+ - `form.*` coercible types (solnic)
1069
+ - `Type::Hash#strict` for defining hashes with a strict schema (solnic)
1070
+ - `Type::Hash#symbolized` for defining hashes that will symbolize keys (solnic)
1071
+ - `Dry::Data.register_class` short-cut interface for registering a class and
543
1072
  setting its `.new` method as the constructor (solnic)
544
- * `Dry::Data::Compiler` for building a type from a simple ast (solnic)
1073
+ - `Dry::Data::Compiler` for building a type from a simple ast (solnic)
1074
+
545
1075
 
546
- [Compare v0.0.1...HEAD](https://github.com/dry-rb/dry-types/compare/v0.0.1...HEAD)
1076
+ [Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-types/compare/v0.0.1...v0.1.0)
547
1077
 
548
- # v0.0.1 2015-10-05
1078
+ ## 0.0.1 2015-10-05
549
1079
 
550
1080
  First public release