dry-struct v1.3.0 Release Notes

Release Date: 2020-02-10 // over 4 years ago
  • โž• 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