dry-rb / dry-struct

Typed struct and value objects
https://dry-rb.org/gems/dry-struct
MIT License
410 stars 62 forks source link

Create base class from optional structs #164

Closed flash-gordon closed 3 years ago

flash-gordon commented 3 years ago

This adds support for inferring base class from optional structs

class User  < Dry::Struct
  attribute :address, Dry::Struct.optional do
    attribute :city, 'string'
  end
end

Resolves #156 It doesn't work in more complex cases like arrays of optionals or optional arrays but I doubt these cases are common enough to bother, there's always another way to implement them.