Releases: dry-rb/dry-struct
Releases · dry-rb/dry-struct
v1.7.0
Fixed
- Fixed coercion errors for structs (issue #192 via #193) (@flash-gordon)
- Invalid method names are now allowed as struct attributes (issue #169 via #195) (@flash-gordon)
Changed
- Missing attribute error now includes the name of the class (issue #170 via #191) (@phillipoertel + @cllns)
- 3.1 is now the minimum Ruby version (@flash-gordon)
Dry::Struct::Error
is now a subclass ofDry::Types::CoercionError
(in #193) (@flash-gordon)Dry::Struct#[]
now returnsnil
if an optional attribute is not set. This is consistent with calling accessor methods for optional attributes. (issue #171 via #194) (@ivleonov + @flash-gordon)
v1.6.0
v1.5.2
Fixed
- Coercion failures keep the original error instead of just having a string (@flash-gordon)
v1.5.1
v1.5.0
v1.4.0
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)
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) # => #<User name="John" address=nil>
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) -
Dry::Struct.abstract
declares a struct class as abstract. An abstract class is used as a default superclass for nested structs (@flash-gordon) -
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)
v1.2.0
1.2.0 2019-12-20
Changed
Dry::Struct::Value
is deprecated.Dry::Struct
instances were never meant to be mutable, we have no support for this. The only difference betweenDry::Struct
andDry::Struct::Value
is that the latter is deeply frozen. Freezing objects slows the code down and gives you very little benefit in return. If you have a use case forValue
, it won't be hard to roll your own solution using ice_nine (flash-gordon)- In the thread of the previous change, structs now use immutable equalizer. This means
Struct#hash
memoizes its value after the first invocation. Depending on the case, this may speed up your code significantly (flash-gordon)
v1.1.1
1.1.1 2019-10-13
Changed
-
Pattern matching syntax is simplified with
deconstruct_keys
(k-tsj)User = Dry.Struct(name: 'string', email: 'string') user = User.new(name: 'John Doe', email: '[email protected]') case user in User(name: 'John Doe', email:) puts email else puts 'Not John' end
See more examples in the specs.
v1.1.0
1.1.0 2019-10-07
Added
-
Experimental support for pattern matching 🎉 (flash-gordon)
User = Dry.Struct(name: 'string', email: 'string') user = User.new(name: 'John Doe', email: '[email protected]') case user in User({ name: 'John Doe', email: }) puts email else puts 'Not John' end
See more examples in the specs.