timriley on remove-auto-register
Remove commented code (compare)
timriley on remove-auto-register
Remove no-longer-relevant doc (compare)
timriley on remove-auto-register
Remove another unneeded splat (compare)
timriley on remove-auto-register
Li’l tweak (compare)
timriley on remove-auto-register
Li’l tweak (compare)
timriley on remove-auto-register
Simplify args passed to build_f… (compare)
timriley on remove-auto-register
Further simplify args for build… (compare)
timriley on remove-auto-register
Remove `auto_register!` and add… Provide the default loader to a… Simplify args passed to build_f… (compare)
timriley on rich-component-dirs-config
Accept plain options hash inste… (compare)
One more thing to add, it isn't just the input_preprocessor
but rather a combination of that and type_specs
set to true
. Looking at OtherSchema
I see that:
OtherSchema.config[:type_map] => {:last_name=>#<Dry::Types::Definition primitive=String options={} meta={}>}
Not that first_name
is not in the type_map
. I haven't done a deep dive into the code yet, but if anyone familiar with the finer points can give me any pointers (or just flat out tell me if this is a bug and, if so, I'll work to patch it) that would be really handy.
Looks like the bug has actually been patched: https://github.com/dry-rb/dry-validation/pull/359/commits/71872da3985c54b6930ed39c42d004f837e9812f
This fixes the behavior. Is there something wrong with this PR?
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 )