Next-gen ruby libs! » github.com/dry-rb » website: https://dry-rb.org » forum: https://discourse.dry-rb.org
.default(false)
for one of the attributes, and I passed nil
it convert it to the default value used
schema
constructor when instantiating my struct from the database, but want to use strict_with_defaults
everywhere else
Struct.constructor
that takes a block
Events::PasswordChanged
class is kind of Events::Update
module Events
class PasswordChanged < Dry::Struct
attribute :user_id, Types::UUID
attribute :password, Types::String
end
class EmailChanged < Dry::Struct
attribute :user_id, Types::UUID
attribute :email, Types::String
end
Updated = PasswordChanged | EmailChanged
end
Events::Update[event]
<- this either will raise an error or return the value back
try
if you don't want to raise an exception, although structs are supposed to be used with valid input where if anything doesn't match the format raises an exception
valid?
is another option