dry-struct v1.4.0 Release Notes

Release Date: 2021-01-21 // about 3 years ago
  • โž• Added

    • ๐Ÿ‘Œ Support for wrapping constructors and fallbacks, see release notes for dry-types 1.5.0 (@flash-gordon)
    • ๐Ÿ‘Œ Improvements of the attribute DSL, now it's possible to use optional structs as a base class (@flash-gordon) ```ruby class User < Dry::Struct attribute :name, Types::String attribute :address, Dry::Struct.optional do attribute :city, Types::String end end

    User.new(name: "John", address: nil) # => #

    
    
    [Compare v1.3.0...v1.4.0](https://github.com/dry-rb/dry-struct/compare/v1.3.0...v1.4.0)
    

Previous changes from v1.3.0

  • โž• Added

    • Nested structures will reuse type and key transformations from the enclosing struct (@flash-gordon)
      class User < Dry::Struct
        transform_keys(&:to_sym)
    
        attribute :name, Types::String
        attribute :address do
          # this struct will inherit transform_keys(&:to_sym)
          attribute :city, Types::String
        end
    
        # nested struct will _not_ transform keys because a parent
        # struct is given
        attribute :contacts, Dry::Struct do
          attribute :email, Types::String
        end
      end
    
    • Dry::Struct::Constructor finally acts like a fully-featured type (@flash-gordon)
    • 0๏ธโƒฃ Dry::Struct.abstract declares a struct class as abstract. An abstract class is used as a default superclass for nested structs (@flash-gordon)
    • Dry::Struct.to_ast and struct compiler (@flash-gordon)
    • Struct composition with Dry::Struct.attributes_from. It's more flexible than inheritance (@waiting-for-dev + @flash-gordon)
      class Address < Dry::Struct
        attribute :city, Types::String
        attribute :zipcode, Types::String
      end
    
      class Buyer < Dry::Struct
        attribute :name, Types::String
        attributes_from Address
      end
    
      class Seller < Dry::Struct
        attribute :name, Types::String
        attribute :email, Types::String
        attributes_from Address
      end
    

    ๐Ÿ”„ Changed

    • ๐Ÿ“‡ [internal] metadata is now stored inside schema (@flash-gordon)

    Compare v1.2.0...v1.3.0