-
-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
956fff2
commit 66fb7cc
Showing
1 changed file
with
63 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,35 @@ | ||
# 1.1.0 2019-10-07 | ||
|
||
## Added | ||
|
||
- Experimental support for pattern matching :tada: (flash-gordon) | ||
|
||
```ruby | ||
User = Dry.Struct(name: 'string', email: 'string') | ||
|
||
user = User.new(name: 'John Doe', email: '[email protected]') | ||
|
||
case user | ||
in User({ name: 'John Doe', email: }) | ||
puts email | ||
else | ||
puts 'Not John' | ||
end | ||
``` | ||
|
||
See more examples in the [specs](https://github.com/dry-rb/dry-struct/blob/956fff208296731c40f1fea04b36106ea01b56d0/spec/dry/struct/pattern_matching_spec.rb). | ||
|
||
[Compare v1.0.0...v1.1.0](https://github.com/dry-rb/dry-struct/compare/v1.0.0...v1.1.0) | ||
|
||
# 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) | ||
- `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) | ||
- `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) | ||
```ruby | ||
User = Dry::Struct(name: 'string') | ||
User.(1) { :oh_no } | ||
|
@@ -19,7 +42,7 @@ | |
|
||
## Changed | ||
|
||
* [BREAKING] `Struct.input` was renamed `Struct.schema`, hence `Struct.schema` returns an instance of `Dry::Types::Hash::Schema` rather than a `Hash`. Schemas are also implementing `Enumerable` but they iterate over key types. | ||
- [BREAKING] `Struct.input` was renamed `Struct.schema`, hence `Struct.schema` returns an instance of `Dry::Types::Hash::Schema` rather than a `Hash`. Schemas are also implementing `Enumerable` but they iterate over key types. | ||
New API: | ||
```ruby | ||
User.schema.each do |key| | ||
|
@@ -31,28 +54,28 @@ | |
```ruby | ||
User.schema.key(:id) # => #<Dry::Types::Hash::Key ...> | ||
``` | ||
* [BREAKING] `transform_types` now passes one argument to the block, an instance of the `Key` type. Combined with the new API from dry-types it simplifies declaring omittable keys: | ||
- [BREAKING] `transform_types` now passes one argument to the block, an instance of the `Key` type. Combined with the new API from dry-types it simplifies declaring omittable keys: | ||
```ruby | ||
class StructWithOptionalKeys < Dry::Struct | ||
transform_types { |key| key.required(false) } | ||
# or simply | ||
transform_types(&:omittable) | ||
end | ||
``` | ||
* `Dry::Stuct#new` is now more efficient for partial updates (flash-gordon) | ||
* Ruby 2.3 is EOL and not officially supported. It may work but we don't test it. | ||
- `Dry::Stuct#new` is now more efficient for partial updates (flash-gordon) | ||
- Ruby 2.3 is EOL and not officially supported. It may work but we don't test it. | ||
|
||
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-struct/compare/v0.6.0...v0.7.0) | ||
|
||
# v0.6.0 2018-10-24 | ||
|
||
## Changed | ||
|
||
* [BREAKING] `Struct.attribute?` in the old sense is deprecated, use `has_attribute?` as a replacement | ||
- [BREAKING] `Struct.attribute?` in the old sense is deprecated, use `has_attribute?` as a replacement | ||
|
||
## Added | ||
|
||
* `Struct.attribute?` is an easy way to define omittable attributes (flash-gordon): | ||
- `Struct.attribute?` is an easy way to define omittable attributes (flash-gordon): | ||
|
||
```ruby | ||
class User < Dry::Struct | ||
|
@@ -64,19 +87,19 @@ | |
|
||
## Fixed | ||
|
||
* `Struct#to_h` recursively converts hash values to hashes, this was done to be consistent with current behavior for arrays (oeoeaio + ZimbiX) | ||
- `Struct#to_h` recursively converts hash values to hashes, this was done to be consistent with current behavior for arrays (oeoeaio + ZimbiX) | ||
|
||
[Compare v0.5.1...v0.6.0](https://github.com/dry-rb/dry-struct/compare/v0.5.1...v0.6.0) | ||
|
||
# v0.5.1 2018-08-11 | ||
|
||
## Fixed | ||
|
||
* Constant resolution is now restricted to the current module when structs are automatically defined using the block syntax. This shouldn't break any existing code (piktur) | ||
- Constant resolution is now restricted to the current module when structs are automatically defined using the block syntax. This shouldn't break any existing code (piktur) | ||
|
||
## Added | ||
|
||
* Pretty print extension (ojab) | ||
- Pretty print extension (ojab) | ||
```ruby | ||
Dry::Struct.load_extensions(:pretty_print) | ||
PP.pp(user) | ||
|
@@ -92,14 +115,14 @@ | |
|
||
## BREAKING CHANGES | ||
|
||
* `constructor_type` was removed, use `transform_types` and `transform_keys` as a replacement (see below) | ||
* Default types are evaluated _only_ on missing values. Again, use `tranform_types` as a work around for `nil`s | ||
* Values are now stored within a single instance variable names `@attributes`, this sped up struct creation and improved support for reserved attribute names such as `hash`, they don't get a getter but still can be read via `#[]` | ||
* Ruby 2.3 is a minimal supported version | ||
- `constructor_type` was removed, use `transform_types` and `transform_keys` as a replacement (see below) | ||
- Default types are evaluated _only_ on missing values. Again, use `tranform_types` as a work around for `nil`s | ||
- Values are now stored within a single instance variable names `@attributes`, this sped up struct creation and improved support for reserved attribute names such as `hash`, they don't get a getter but still can be read via `#[]` | ||
- Ruby 2.3 is a minimal supported version | ||
|
||
## Added | ||
|
||
* `Dry::Struct.transform_types` accepts a block which is yielded on every type to add. Since types are `dry-types`' objects that come with a robust DSL it's rather simple to restore the behavior of `constructor_type`. See https://github.com/dry-rb/dry-struct/pull/64 for details (flash-gordon) | ||
- `Dry::Struct.transform_types` accepts a block which is yielded on every type to add. Since types are `dry-types`' objects that come with a robust DSL it's rather simple to restore the behavior of `constructor_type`. See https://github.com/dry-rb/dry-struct/pull/64 for details (flash-gordon) | ||
|
||
Example: evaluate defaults on `nil` values | ||
|
||
|
@@ -111,17 +134,17 @@ | |
end | ||
``` | ||
|
||
* `Data::Struct.transform_keys` accepts a block/proc that transforms keys of input hashes. The most obvious usage is simbolization but arbitrary transformations are allowed (flash-gordon) | ||
- `Data::Struct.transform_keys` accepts a block/proc that transforms keys of input hashes. The most obvious usage is simbolization but arbitrary transformations are allowed (flash-gordon) | ||
|
||
* `Dry.Struct` builds a struct by a hash of attribute names and types (citizen428) | ||
- `Dry.Struct` builds a struct by a hash of attribute names and types (citizen428) | ||
|
||
```ruby | ||
User = Dry::Struct(name: 'strict.string') do | ||
attribute :email, 'strict.string' | ||
end | ||
``` | ||
|
||
* Support for `Struct.meta`, note that `.meta` returns a _new class_ (flash-gordon) | ||
- Support for `Struct.meta`, note that `.meta` returns a _new class_ (flash-gordon) | ||
|
||
```ruby | ||
class User < Dry::Struct | ||
|
@@ -133,7 +156,7 @@ | |
User.new(name: 'Jade').class == UserWithMeta.new(name: 'Jade').class # => false | ||
``` | ||
|
||
* `Struct.attribute` yields a block with definition for nested structs. It defines a nested constant for the new struct and supports arrays (AMHOL + flash-gordon) | ||
- `Struct.attribute` yields a block with definition for nested structs. It defines a nested constant for the new struct and supports arrays (AMHOL + flash-gordon) | ||
|
||
```ruby | ||
class User < Dry::Struct | ||
|
@@ -153,87 +176,87 @@ | |
|
||
## Fixed | ||
|
||
* Adding a new attribute invalidates `attribute_names` (flash-gordon) | ||
* Struct classes track subclasses and define attributes in them, now it doesn't matter whether you define attributes first and _then_ subclass or vice versa. Note this can lead to memory leaks in Rails environment when struct classes are reloaded (flash-gordon) | ||
- Adding a new attribute invalidates `attribute_names` (flash-gordon) | ||
- Struct classes track subclasses and define attributes in them, now it doesn't matter whether you define attributes first and _then_ subclass or vice versa. Note this can lead to memory leaks in Rails environment when struct classes are reloaded (flash-gordon) | ||
|
||
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-struct/compare/v0.4.0...v0.5.0) | ||
|
||
# v0.4.0 2017-11-04 | ||
|
||
## Changed | ||
|
||
* Attribute readers don't override existing instance methods (solnic) | ||
* `Struct#new` uses raw attributes instead of method calls, this makes the behavior consistent with the change above (flash-gordon) | ||
* `constructor_type` now actively rejects `:weak` and `:symbolized` values (GustavoCaso) | ||
- Attribute readers don't override existing instance methods (solnic) | ||
- `Struct#new` uses raw attributes instead of method calls, this makes the behavior consistent with the change above (flash-gordon) | ||
- `constructor_type` now actively rejects `:weak` and `:symbolized` values (GustavoCaso) | ||
|
||
## Fixed | ||
|
||
* `Struct#new` doesn't call `.to_hash` recursively (flash-gordon) | ||
- `Struct#new` doesn't call `.to_hash` recursively (flash-gordon) | ||
|
||
[Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-struct/compare/v0.3.1...v0.4.0) | ||
|
||
# v0.3.1 2017-06-30 | ||
|
||
## Added | ||
|
||
* `Struct.constructor` that makes dry-struct more aligned with dry-types; now you can have a struct with a custom constructor that will be called _before_ calling the `new` method (v-kolesnikov) | ||
* `Struct.attribute?` and `Struct.attribute_names` for introspecting struct attributes (flash-gordon) | ||
* `Struct#__new__` is a safe-to-use-in-gems alias for `Struct#new` (flash-gordon) | ||
- `Struct.constructor` that makes dry-struct more aligned with dry-types; now you can have a struct with a custom constructor that will be called _before_ calling the `new` method (v-kolesnikov) | ||
- `Struct.attribute?` and `Struct.attribute_names` for introspecting struct attributes (flash-gordon) | ||
- `Struct#__new__` is a safe-to-use-in-gems alias for `Struct#new` (flash-gordon) | ||
|
||
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-struct/compare/v0.3.0...v0.3.1) | ||
|
||
# v0.3.0 2017-05-05 | ||
|
||
## Added | ||
|
||
* `Dry::Struct#new` method to return new instance with applied changeset (Kukunin) | ||
- `Dry::Struct#new` method to return new instance with applied changeset (Kukunin) | ||
|
||
## Fixed | ||
|
||
* `.[]` and `.call` does not coerce subclass to superclass anymore (Kukunin) | ||
* Raise ArgumentError when attribute type is a string and no value provided is for `new` (GustavoCaso) | ||
- `.[]` and `.call` does not coerce subclass to superclass anymore (Kukunin) | ||
- Raise ArgumentError when attribute type is a string and no value provided is for `new` (GustavoCaso) | ||
|
||
## Changed | ||
|
||
* `.new` without arguments doesn't use nil as an input for non-default types anymore (flash-gordon) | ||
- `.new` without arguments doesn't use nil as an input for non-default types anymore (flash-gordon) | ||
|
||
[Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-struct/compare/v0.2.1...v0.3.0) | ||
|
||
# v0.2.1 2017-02-27 | ||
|
||
## Fixed | ||
|
||
* Fixed `Dry::Struct::Value` which appeared to be broken in the last release (flash-gordon) | ||
- Fixed `Dry::Struct::Value` which appeared to be broken in the last release (flash-gordon) | ||
|
||
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-struct/compare/v0.2.0...v0.2.1) | ||
|
||
# v0.2.0 2016-02-26 | ||
|
||
## Changed | ||
|
||
* Struct attributes can be overridden in a subclass (flash-gordon) | ||
- Struct attributes can be overridden in a subclass (flash-gordon) | ||
|
||
[Compare v0.1.1...v0.2.0](https://github.com/dry-rb/dry-struct/compare/v0.1.1...v0.2.0) | ||
|
||
# v0.1.1 2016-11-13 | ||
|
||
## Fixed | ||
|
||
* Make `Dry::Struct` act as a constrained type. This fixes the behavior of sum types containing structs (flash-gordon) | ||
- Make `Dry::Struct` act as a constrained type. This fixes the behavior of sum types containing structs (flash-gordon) | ||
|
||
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-struct/compare/v0.1.0...v0.1.1) | ||
|
||
# v0.1.0 2016-09-21 | ||
|
||
## Added | ||
|
||
* `:strict_with_defaults` constructor type (backus) | ||
- `:strict_with_defaults` constructor type (backus) | ||
|
||
## Changed | ||
|
||
* [BREAKING] `:strict` was renamed to `:permissive` as it ignores missing keys (backus) | ||
* [BREAKING] `:strict` now raises on unexpected keys (backus) | ||
* Structs no longer auto-register themselves in the types container as they implement `Type` interface and we don't have to wrap them in `Type::Definition` (flash-gordon) | ||
- [BREAKING] `:strict` was renamed to `:permissive` as it ignores missing keys (backus) | ||
- [BREAKING] `:strict` now raises on unexpected keys (backus) | ||
- Structs no longer auto-register themselves in the types container as they implement `Type` interface and we don't have to wrap them in `Type::Definition` (flash-gordon) | ||
|
||
[Compare v0.0.1...v0.1.0](https://github.com/dry-rb/dry-struct/compare/v0.0.1...v0.1.0) | ||
|
||
|