currently when a struct is non-strict and an attribute is optional. calling attributes
return a hash which doesn’t not include the attribute with nil value.
it might not be consistent with the attribute_names, because it has all the attributes.
So thinking to have a new method ‘full_attributes’ to return all the available attributes ,even though some values are nil.
module Types
include Dry.Types()
end
[2] pry(main)> class User < Dry::Struct
[2] pry(main)* schema schema.strict(false)
[2] pry(main)* attribute? :name, Types::String.optional
[2] pry(main)* attribute? :age, Types::Integer.optional
[2] pry(main)* end
=> User
[3] pry(main)> User.attribute_names
=> [:name, :age]
[4] pry(main)> u = User.new(name: 'a')
=> #<User name="a" age=nil>
[5] pry(main)> u.attributes
=> {:name=>"a"}
hoping to have a method to return {name: ‘a’, age: nil}, no matter it is called full_attributes or whatever.