dry-struct v1.4.0 Release Notes
Release Date: 2021-01-21 // over 3 years ago-
โ Added
- ๐ Support for wrapping constructors and fallbacks, see release notes for dry-types 1.5.0 (@flash-gordon)
- ๐ Improvements of the attribute DSL, now it's possible to use optional structs as a base class (@flash-gordon) ```ruby class User < Dry::Struct attribute :name, Types::String attribute :address, Dry::Struct.optional do attribute :city, Types::String end end
User.new(name: "John", address: nil) # => #
[Compare v1.3.0...v1.4.0](https://github.com/dry-rb/dry-struct/compare/v1.3.0...v1.4.0)
Previous changes from v1.3.0
-
โ Added
- Nested structures will reuse type and key transformations from the enclosing struct (@flash-gordon)
class User < Dry::Struct transform_keys(&:to_sym) attribute :name, Types::String attribute :address do # this struct will inherit transform_keys(&:to_sym) attribute :city, Types::String end # nested struct will _not_ transform keys because a parent # struct is given attribute :contacts, Dry::Struct do attribute :email, Types::String end end
Dry::Struct::Constructor
finally acts like a fully-featured type (@flash-gordon)- 0๏ธโฃ
Dry::Struct.abstract
declares a struct class as abstract. An abstract class is used as a default superclass for nested structs (@flash-gordon) Dry::Struct.to_ast
and struct compiler (@flash-gordon)- Struct composition with
Dry::Struct.attributes_from
. It's more flexible than inheritance (@waiting-for-dev + @flash-gordon)
class Address < Dry::Struct attribute :city, Types::String attribute :zipcode, Types::String end class Buyer < Dry::Struct attribute :name, Types::String attributes_from Address end class Seller < Dry::Struct attribute :name, Types::String attribute :email, Types::String attributes_from Address end
๐ Changed
- ๐ [internal] metadata is now stored inside schema (@flash-gordon)