dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
dry-bot on master
[devtools] sync (compare)
constructor_type
. Can someone point me in the direction of how to make all attributes omittable, without explicitly having to set .meta(omittable: true)
? I used constructor_type :schema
to get around it before..
class User < Dry::Struct
transform_types do |type|
type.meta(omittable: true)
end
attribute :name, Types::Strict::String
attribute :age, Types::Strict::Integer.default(18)
end
class User < Dry::Struct
transform_types do |type|
type.meta(omittable: true)
end
attribute :foo, Types::Hash.default(Hash.new)
end
User.new.foo # => {:meta=>{:omittable=>true}}
Dry::Struct::Error: [User.new] :name is missing in Hash input
User.new.foo # => {:meta=>{:omittable=>true}}
I'm trying to get User.new.foo # => {}
(which is what constructor_type :schema
did before)
class User < Dry::Struct
transform_types do |type|
type.optional.deafult({})
end
attribute :foo, Types::Hash
end
class User < Dry::Struct
transform_types do |type|
if type.default?
type
else
type.meta(omittable: true)
end
end
attribute :foo, Types::Hash.default({})
attribute :bar, Types::String
end
User.new
=> #<User foo={} bar=nil>
transform_types
many times
constructor_type :schema
style :P )