Skip to content

Commit 4f06831

Browse files
authored
Update CHANGELOG [skip ci]
1 parent 1264e86 commit 4f06831

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* `constructor_type` was removed, use `transform_types` and `transform_keys` as a replacement (see below)
66
* Default types are evaluated _only_ on missing values. Again, use `tranform_types` as a work around for `nil`s
7+
* 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 `#[]`
8+
* Ruby 2.3 is a minimal supported version
79

810
## Added
911

@@ -40,10 +42,29 @@
4042

4143
User.new(name: 'Jade').class == UserWithMeta.new(name: 'Jade').class # => false
4244
```
45+
46+
* `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)
47+
48+
```ruby
49+
class User < Dry::Struct
50+
attribute :name, Types::Strict::String
51+
attribute :address do
52+
attribute :country, Types::Strict::String
53+
attribute :city, Types::Strict::String
54+
end
55+
attribute :accounts, Types::Strict::Array do
56+
attribute :currency, Types::Strict::String
57+
attribute :balance, Types::Strict::Decimal
58+
end
59+
end
60+
61+
# ^This automatically defines User::Address and User::Account
62+
```
4363

4464
## Fixed
4565

4666
* Adding a new attribute invalidates `attribute_names` (flash-gordon)
67+
* 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)
4768

4869
[Compare v0.4.0...master](https://github.com/dry-rb/dry-struct/compare/v0.4.0...master)
4970

0 commit comments

Comments
 (0)