How do you allow a missing attribute for dry-struct/dry-types? In the following code I would not always want have to provide the “interesting_fact” attribute.
I see mention of “maybe” in the introduction documentation: http://dry-rb.org/gems/dry-types/optional-values/
…but I haven’t been able to apply it.
require 'dry-struct'
#require 'dry-types' needed?
module Types
include Dry::Types.module
end
class User < Dry::Struct
attribute :name, Types::String.optional
attribute :interesting_fact, Types::String
end
user = User.new(name: nil)
#-> error :interesting_fact is missing in Hash input
…trying to use maybe results in constant undefined
Types::Maybe::Coercible
# -> error uninitialized constant Types (NameError)