|
| 1 | +# 1.1.0 2019-10-07 |
| 2 | + |
| 3 | +## Added |
| 4 | + |
| 5 | +- Experimental support for pattern matching :tada: (flash-gordon) |
| 6 | + |
| 7 | + ```ruby |
| 8 | + User = Dry.Struct(name: 'string', email: 'string') |
| 9 | + |
| 10 | + user = User. new( name: 'John Doe', email: '[email protected]') |
| 11 | + |
| 12 | + case user |
| 13 | + in User({ name: 'John Doe', email: }) |
| 14 | + puts email |
| 15 | + else |
| 16 | + puts 'Not John' |
| 17 | + end |
| 18 | + ``` |
| 19 | + |
| 20 | + See more examples in the [specs](https://github.com/dry-rb/dry-struct/blob/956fff208296731c40f1fea04b36106ea01b56d0/spec/dry/struct/pattern_matching_spec.rb). |
| 21 | + |
| 22 | +[Compare v1.0.0...v1.1.0](https://github.com/dry-rb/dry-struct/compare/v1.0.0...v1.1.0) |
| 23 | + |
1 | 24 | # 1.0.0 2019-04-23 |
2 | 25 |
|
3 | 26 | ## Changed |
4 | 27 |
|
5 | | -* `valid?` and `===` behave differently, `===` works the same way `Class#===` does and `valid?` checks if the value _can be_ coerced to the struct (flash-gordon) |
| 28 | +- `valid?` and `===` behave differently, `===` works the same way `Class#===` does and `valid?` checks if the value _can be_ coerced to the struct (flash-gordon) |
6 | 29 |
|
7 | 30 | ## Added |
8 | 31 |
|
9 | | -* `Struct.call` now accepts an optional block that will be called on failed coercion. This behavior is consistent with dry-types 1.0. Note that `.new` doesn't take a block (flash-gordon) |
| 32 | +- `Struct.call` now accepts an optional block that will be called on failed coercion. This behavior is consistent with dry-types 1.0. Note that `.new` doesn't take a block (flash-gordon) |
10 | 33 | ```ruby |
11 | 34 | User = Dry::Struct(name: 'string') |
12 | 35 | User.(1) { :oh_no } |
|
19 | 42 |
|
20 | 43 | ## Changed |
21 | 44 |
|
22 | | -* [BREAKING] `Struct.input` was renamed `Struct.schema`, hence `Struct.schema` returns an instance of `Dry::Types::Hash::Schema` rather than a `Hash`. Schemas are also implementing `Enumerable` but they iterate over key types. |
| 45 | +- [BREAKING] `Struct.input` was renamed `Struct.schema`, hence `Struct.schema` returns an instance of `Dry::Types::Hash::Schema` rather than a `Hash`. Schemas are also implementing `Enumerable` but they iterate over key types. |
23 | 46 | New API: |
24 | 47 | ```ruby |
25 | 48 | User.schema.each do |key| |
|
31 | 54 | ```ruby |
32 | 55 | User.schema.key(:id) # => #<Dry::Types::Hash::Key ...> |
33 | 56 | ``` |
34 | | -* [BREAKING] `transform_types` now passes one argument to the block, an instance of the `Key` type. Combined with the new API from dry-types it simplifies declaring omittable keys: |
| 57 | +- [BREAKING] `transform_types` now passes one argument to the block, an instance of the `Key` type. Combined with the new API from dry-types it simplifies declaring omittable keys: |
35 | 58 | ```ruby |
36 | 59 | class StructWithOptionalKeys < Dry::Struct |
37 | 60 | transform_types { |key| key.required(false) } |
38 | 61 | # or simply |
39 | 62 | transform_types(&:omittable) |
40 | 63 | end |
41 | 64 | ``` |
42 | | -* `Dry::Stuct#new` is now more efficient for partial updates (flash-gordon) |
43 | | -* Ruby 2.3 is EOL and not officially supported. It may work but we don't test it. |
| 65 | +- `Dry::Stuct#new` is now more efficient for partial updates (flash-gordon) |
| 66 | +- Ruby 2.3 is EOL and not officially supported. It may work but we don't test it. |
44 | 67 |
|
45 | 68 | [Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-struct/compare/v0.6.0...v0.7.0) |
46 | 69 |
|
47 | 70 | # v0.6.0 2018-10-24 |
48 | 71 |
|
49 | 72 | ## Changed |
50 | 73 |
|
51 | | -* [BREAKING] `Struct.attribute?` in the old sense is deprecated, use `has_attribute?` as a replacement |
| 74 | +- [BREAKING] `Struct.attribute?` in the old sense is deprecated, use `has_attribute?` as a replacement |
52 | 75 |
|
53 | 76 | ## Added |
54 | 77 |
|
55 | | -* `Struct.attribute?` is an easy way to define omittable attributes (flash-gordon): |
| 78 | +- `Struct.attribute?` is an easy way to define omittable attributes (flash-gordon): |
56 | 79 |
|
57 | 80 | ```ruby |
58 | 81 | class User < Dry::Struct |
|
64 | 87 |
|
65 | 88 | ## Fixed |
66 | 89 |
|
67 | | -* `Struct#to_h` recursively converts hash values to hashes, this was done to be consistent with current behavior for arrays (oeoeaio + ZimbiX) |
| 90 | +- `Struct#to_h` recursively converts hash values to hashes, this was done to be consistent with current behavior for arrays (oeoeaio + ZimbiX) |
68 | 91 |
|
69 | 92 | [Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-struct/compare/v0.5.1...v0.6.0) |
70 | 93 |
|
71 | 94 | # v0.5.1 2018-08-11 |
72 | 95 |
|
73 | 96 | ## Fixed |
74 | 97 |
|
75 | | -* Constant resolution is now restricted to the current module when structs are automatically defined using the block syntax. This shouldn't break any existing code (piktur) |
| 98 | +- Constant resolution is now restricted to the current module when structs are automatically defined using the block syntax. This shouldn't break any existing code (piktur) |
76 | 99 |
|
77 | 100 | ## Added |
78 | 101 |
|
79 | | -* Pretty print extension (ojab) |
| 102 | +- Pretty print extension (ojab) |
80 | 103 | ```ruby |
81 | 104 | Dry::Struct.load_extensions(:pretty_print) |
82 | 105 | PP.pp(user) |
|
92 | 115 |
|
93 | 116 | ## BREAKING CHANGES |
94 | 117 |
|
95 | | -* `constructor_type` was removed, use `transform_types` and `transform_keys` as a replacement (see below) |
96 | | -* Default types are evaluated _only_ on missing values. Again, use `tranform_types` as a work around for `nil`s |
97 | | -* Values are now stored within a single instance variable names `@attributes`, this sped up struct creation and improved support for reserved attribute names such as `hash`, they don't get a getter but still can be read via `#[]` |
98 | | -* Ruby 2.3 is a minimal supported version |
| 118 | +- `constructor_type` was removed, use `transform_types` and `transform_keys` as a replacement (see below) |
| 119 | +- Default types are evaluated _only_ on missing values. Again, use `tranform_types` as a work around for `nil`s |
| 120 | +- Values are now stored within a single instance variable names `@attributes`, this sped up struct creation and improved support for reserved attribute names such as `hash`, they don't get a getter but still can be read via `#[]` |
| 121 | +- Ruby 2.3 is a minimal supported version |
99 | 122 |
|
100 | 123 | ## Added |
101 | 124 |
|
102 | | -* `Dry::Struct.transform_types` accepts a block which is yielded on every type to add. Since types are `dry-types`' objects that come with a robust DSL it's rather simple to restore the behavior of `constructor_type`. See https://github.com/dry-rb/dry-struct/pull/64 for details (flash-gordon) |
| 125 | +- `Dry::Struct.transform_types` accepts a block which is yielded on every type to add. Since types are `dry-types`' objects that come with a robust DSL it's rather simple to restore the behavior of `constructor_type`. See https://github.com/dry-rb/dry-struct/pull/64 for details (flash-gordon) |
103 | 126 |
|
104 | 127 | Example: evaluate defaults on `nil` values |
105 | 128 |
|
|
111 | 134 | end |
112 | 135 | ``` |
113 | 136 |
|
114 | | -* `Data::Struct.transform_keys` accepts a block/proc that transforms keys of input hashes. The most obvious usage is simbolization but arbitrary transformations are allowed (flash-gordon) |
| 137 | +- `Data::Struct.transform_keys` accepts a block/proc that transforms keys of input hashes. The most obvious usage is simbolization but arbitrary transformations are allowed (flash-gordon) |
115 | 138 |
|
116 | | -* `Dry.Struct` builds a struct by a hash of attribute names and types (citizen428) |
| 139 | +- `Dry.Struct` builds a struct by a hash of attribute names and types (citizen428) |
117 | 140 |
|
118 | 141 | ```ruby |
119 | 142 | User = Dry::Struct(name: 'strict.string') do |
120 | 143 | attribute :email, 'strict.string' |
121 | 144 | end |
122 | 145 | ``` |
123 | 146 |
|
124 | | -* Support for `Struct.meta`, note that `.meta` returns a _new class_ (flash-gordon) |
| 147 | +- Support for `Struct.meta`, note that `.meta` returns a _new class_ (flash-gordon) |
125 | 148 |
|
126 | 149 | ```ruby |
127 | 150 | class User < Dry::Struct |
|
133 | 156 | User.new(name: 'Jade').class == UserWithMeta.new(name: 'Jade').class # => false |
134 | 157 | ``` |
135 | 158 |
|
136 | | -* `Struct.attribute` yields a block with definition for nested structs. It defines a nested constant for the new struct and supports arrays (AMHOL + flash-gordon) |
| 159 | +- `Struct.attribute` yields a block with definition for nested structs. It defines a nested constant for the new struct and supports arrays (AMHOL + flash-gordon) |
137 | 160 |
|
138 | 161 | ```ruby |
139 | 162 | class User < Dry::Struct |
|
153 | 176 |
|
154 | 177 | ## Fixed |
155 | 178 |
|
156 | | -* Adding a new attribute invalidates `attribute_names` (flash-gordon) |
157 | | -* Struct classes track subclasses and define attributes in them, now it doesn't matter whether you define attributes first and _then_ subclass or vice versa. Note this can lead to memory leaks in Rails environment when struct classes are reloaded (flash-gordon) |
| 179 | +- Adding a new attribute invalidates `attribute_names` (flash-gordon) |
| 180 | +- Struct classes track subclasses and define attributes in them, now it doesn't matter whether you define attributes first and _then_ subclass or vice versa. Note this can lead to memory leaks in Rails environment when struct classes are reloaded (flash-gordon) |
158 | 181 |
|
159 | 182 | [Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-struct/compare/v0.4.0...v0.5.0) |
160 | 183 |
|
161 | 184 | # v0.4.0 2017-11-04 |
162 | 185 |
|
163 | 186 | ## Changed |
164 | 187 |
|
165 | | -* Attribute readers don't override existing instance methods (solnic) |
166 | | -* `Struct#new` uses raw attributes instead of method calls, this makes the behavior consistent with the change above (flash-gordon) |
167 | | -* `constructor_type` now actively rejects `:weak` and `:symbolized` values (GustavoCaso) |
| 188 | +- Attribute readers don't override existing instance methods (solnic) |
| 189 | +- `Struct#new` uses raw attributes instead of method calls, this makes the behavior consistent with the change above (flash-gordon) |
| 190 | +- `constructor_type` now actively rejects `:weak` and `:symbolized` values (GustavoCaso) |
168 | 191 |
|
169 | 192 | ## Fixed |
170 | 193 |
|
171 | | -* `Struct#new` doesn't call `.to_hash` recursively (flash-gordon) |
| 194 | +- `Struct#new` doesn't call `.to_hash` recursively (flash-gordon) |
172 | 195 |
|
173 | 196 | [Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-struct/compare/v0.3.1...v0.4.0) |
174 | 197 |
|
175 | 198 | # v0.3.1 2017-06-30 |
176 | 199 |
|
177 | 200 | ## Added |
178 | 201 |
|
179 | | -* `Struct.constructor` that makes dry-struct more aligned with dry-types; now you can have a struct with a custom constructor that will be called _before_ calling the `new` method (v-kolesnikov) |
180 | | -* `Struct.attribute?` and `Struct.attribute_names` for introspecting struct attributes (flash-gordon) |
181 | | -* `Struct#__new__` is a safe-to-use-in-gems alias for `Struct#new` (flash-gordon) |
| 202 | +- `Struct.constructor` that makes dry-struct more aligned with dry-types; now you can have a struct with a custom constructor that will be called _before_ calling the `new` method (v-kolesnikov) |
| 203 | +- `Struct.attribute?` and `Struct.attribute_names` for introspecting struct attributes (flash-gordon) |
| 204 | +- `Struct#__new__` is a safe-to-use-in-gems alias for `Struct#new` (flash-gordon) |
182 | 205 |
|
183 | 206 | [Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-struct/compare/v0.3.0...v0.3.1) |
184 | 207 |
|
185 | 208 | # v0.3.0 2017-05-05 |
186 | 209 |
|
187 | 210 | ## Added |
188 | 211 |
|
189 | | -* `Dry::Struct#new` method to return new instance with applied changeset (Kukunin) |
| 212 | +- `Dry::Struct#new` method to return new instance with applied changeset (Kukunin) |
190 | 213 |
|
191 | 214 | ## Fixed |
192 | 215 |
|
193 | | -* `.[]` and `.call` does not coerce subclass to superclass anymore (Kukunin) |
194 | | -* Raise ArgumentError when attribute type is a string and no value provided is for `new` (GustavoCaso) |
| 216 | +- `.[]` and `.call` does not coerce subclass to superclass anymore (Kukunin) |
| 217 | +- Raise ArgumentError when attribute type is a string and no value provided is for `new` (GustavoCaso) |
195 | 218 |
|
196 | 219 | ## Changed |
197 | 220 |
|
198 | | -* `.new` without arguments doesn't use nil as an input for non-default types anymore (flash-gordon) |
| 221 | +- `.new` without arguments doesn't use nil as an input for non-default types anymore (flash-gordon) |
199 | 222 |
|
200 | 223 | [Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-struct/compare/v0.2.1...v0.3.0) |
201 | 224 |
|
202 | 225 | # v0.2.1 2017-02-27 |
203 | 226 |
|
204 | 227 | ## Fixed |
205 | 228 |
|
206 | | -* Fixed `Dry::Struct::Value` which appeared to be broken in the last release (flash-gordon) |
| 229 | +- Fixed `Dry::Struct::Value` which appeared to be broken in the last release (flash-gordon) |
207 | 230 |
|
208 | 231 | [Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-struct/compare/v0.2.0...v0.2.1) |
209 | 232 |
|
210 | 233 | # v0.2.0 2016-02-26 |
211 | 234 |
|
212 | 235 | ## Changed |
213 | 236 |
|
214 | | -* Struct attributes can be overridden in a subclass (flash-gordon) |
| 237 | +- Struct attributes can be overridden in a subclass (flash-gordon) |
215 | 238 |
|
216 | 239 | [Compare v0.1.1...v0.2.0](https://github.com/dry-rb/dry-struct/compare/v0.1.1...v0.2.0) |
217 | 240 |
|
218 | 241 | # v0.1.1 2016-11-13 |
219 | 242 |
|
220 | 243 | ## Fixed |
221 | 244 |
|
222 | | -* Make `Dry::Struct` act as a constrained type. This fixes the behavior of sum types containing structs (flash-gordon) |
| 245 | +- Make `Dry::Struct` act as a constrained type. This fixes the behavior of sum types containing structs (flash-gordon) |
223 | 246 |
|
224 | 247 | [Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-struct/compare/v0.1.0...v0.1.1) |
225 | 248 |
|
226 | 249 | # v0.1.0 2016-09-21 |
227 | 250 |
|
228 | 251 | ## Added |
229 | 252 |
|
230 | | -* `:strict_with_defaults` constructor type (backus) |
| 253 | +- `:strict_with_defaults` constructor type (backus) |
231 | 254 |
|
232 | 255 | ## Changed |
233 | 256 |
|
234 | | -* [BREAKING] `:strict` was renamed to `:permissive` as it ignores missing keys (backus) |
235 | | -* [BREAKING] `:strict` now raises on unexpected keys (backus) |
236 | | -* Structs no longer auto-register themselves in the types container as they implement `Type` interface and we don't have to wrap them in `Type::Definition` (flash-gordon) |
| 257 | +- [BREAKING] `:strict` was renamed to `:permissive` as it ignores missing keys (backus) |
| 258 | +- [BREAKING] `:strict` now raises on unexpected keys (backus) |
| 259 | +- Structs no longer auto-register themselves in the types container as they implement `Type` interface and we don't have to wrap them in `Type::Definition` (flash-gordon) |
237 | 260 |
|
238 | 261 | [Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-struct/compare/v0.0.1...v0.1.0) |
239 | 262 |
|
|
0 commit comments