Skip to content

Releases: dry-rb/dry-struct

v1.6.0

04 Nov 17:52
v1.6.0
Compare
Choose a tag to compare

Changed

Compare v1.5.2...v1.6.0

v1.5.2

19 Oct 08:43
v1.5.2
Compare
Choose a tag to compare

Fixed

  • Coercion failures keep the original error instead of just having a string (@flash-gordon)

Compare v1.5.1...v1.5.2

v1.5.1

17 Oct 14:11
v1.5.1
Compare
Choose a tag to compare

Fixed

  • Fixed issues with auto-loading Extensions module (issue #183 fixed via #184) (@solnic)

Compare v1.5.0...v1.5.1

v1.5.0

15 Oct 05:40
v1.5.0
01b3a4b
Compare
Choose a tag to compare

Changed

Compare v1.4.0...v1.5.0

v1.4.0

21 Jan 18:59
v1.4.0
Compare
Choose a tag to compare

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)
    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) # => #<User name="John" address=nil>

Compare v1.3.0...v1.4.0

v1.3.0

10 Feb 15:00
v1.3.0
950e681
Compare
Choose a tag to compare

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)

  • Dry::Struct.abstract declares a struct class as abstract. An abstract class is used as a default superclass for nested structs (@flash-gordon)

  • 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

v1.2.0

20 Dec 08:52
v1.2.0
93aeb2a
Compare
Choose a tag to compare

1.2.0 2019-12-20

Changed

  • Dry::Struct::Value is deprecated. Dry::Struct instances were never meant to be mutable, we have no support for this. The only difference between Dry::Struct and Dry::Struct::Value is that the latter is deeply frozen. Freezing objects slows the code down and gives you very little benefit in return. If you have a use case for Value, it won't be hard to roll your own solution using ice_nine (flash-gordon)
  • In the thread of the previous change, structs now use immutable equalizer. This means Struct#hash memoizes its value after the first invocation. Depending on the case, this may speed up your code significantly (flash-gordon)

Compare v1.1.1...v1.2.0

v1.1.1

13 Oct 11:21
v1.1.1
e1fc3f0
Compare
Choose a tag to compare

1.1.1 2019-10-13

Changed

  • Pattern matching syntax is simplified with deconstruct_keys (k-tsj)

    User = Dry.Struct(name: 'string', email: 'string')
    
    user = User.new(name: 'John Doe', email: 'john@acme.org')
    
    case user
    in User(name: 'John Doe', email:)
      puts email
    else
      puts 'Not John'
    end

    See more examples in the specs.

Compare v1.1.0...v1.1.1

v1.1.0

07 Oct 09:35
v1.1.0
66fb7cc
Compare
Choose a tag to compare

1.1.0 2019-10-07

Added

  • Experimental support for pattern matching 🎉 (flash-gordon)

    User = Dry.Struct(name: 'string', email: 'string')
    
    user = User.new(name: 'John Doe', email: 'john@acme.org')
    
    case user
    in User({ name: 'John Doe', email: })
      puts email
    else
      puts 'Not John'
    end

    See more examples in the specs.

Compare v1.0.0...v1.1.0

v1.0.0

07 Oct 09:34
v1.0.0
d8af8b9
Compare
Choose a tag to compare

1.0.0 2019-04-23

Changed

  • valid? and === behave differently, === works the same way Class#=== does and valid? checks if the value can be coerced to the struct (flash-gordon)

Added

  • Struct.call now accepts an optional block that will be called on failed coercion. This behavior is consistent with dry-types 1.0. Note that .new doesn't take a block (flash-gordon)
    User = Dry::Struct(name: 'string')
    User.(1) { :oh_no }
    # => :oh_no

Compare v0.7.0...v1.0.0