Skip to content

Releases: dry-rb/dry-struct

v1.8.0

09 Mar 19:16
v1.8.0
Compare
Choose a tag to compare

Added

  • Added super_diff extension for improved struct diffing in RSpec tests (@flash-gordon in #197)

    Add this to your Gemfile:

    gem 'super_diff', group: :test

    Then activate the extension in your spec_helper:

    Dry::Struct.load_extensions(:super_diff)

    Now this

      expected: #<Test::User name="Jane" age=22>
            got: #<Test::User name="Jane" age=21>
    
      (compared using eql?)
    
      Diff:
      @@ -1 +1 @@
      -#<Test::User name="Jane" age=22>
      +#<Test::User name="Jane" age=21>

    will become this:

      expected: #<Test::User name: "Jane", age: 22>
            got: #<Test::User name: "Jane", age: 21>
    
      (compared using eql?)
    
        #<Test::User {
          name: "Jane",
      -   age: 22
      +   age: 21
        }>

Compare v1.7.1...v1.8.0

v1.7.1

31 Jan 11:26
v1.7.1
fd68fd9
Compare
Choose a tag to compare

v1.7.0

06 Jan 14:06
v1.7.0
777c132
Compare
Choose a tag to compare

Fixed

Changed

  • Missing attribute error now includes the name of the class (issue #170 via #191) (@phillipoertel + @cllns)
  • 3.1 is now the minimum Ruby version (@flash-gordon)
  • Dry::Struct::Error is now a subclass of Dry::Types::CoercionError (in #193) (@flash-gordon)
  • Dry::Struct#[] now returns nil if an optional attribute is not set. This is consistent with calling accessor methods for optional attributes. (issue #171 via #194) (@ivleonov + @flash-gordon)

Compare v1.6.0...v1.7.0

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