philiprehberger-struct_kit 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 060eddbc858baf2efcdca822e058cec8816d86e3fadc155ec945af905ee396d6
4
- data.tar.gz: 5e2701e97abcf3e3b714169cb2eea451d4c4f8fb3eec05daec75bbf09595ec24
3
+ metadata.gz: 0a50ed52bad42906d2452f7e16fa3713287f263582554a7f8d67ab404a47d65e
4
+ data.tar.gz: a4e55b469fc1e50ca7388f66b309f69d3046a2100b58c50fb88a06c67150799e
5
5
  SHA512:
6
- metadata.gz: 463cba608aa49db99449dc5064ca41664d13ac0a8cb919b995d2dd2928c2d731a5361aac0bc1dadc3e4b0f93087037eaf250b8a301a2999f26e0c33dead47bbd
7
- data.tar.gz: 57d159e69465225e616471143a80a6758ab3217c804c46f6c99e62d65d34577c78523301228c8744d00bee9cb3fbe680cb8f35790616e9b2da00acac1271d7cc
6
+ metadata.gz: 92f45e162b4c8e851bf33345ecc19bdbfd37a171174dd2a76351e98462bb0f44052b079a12651dd935aa46729e7368755c8b0926060e6c51af3411bd8907ed43
7
+ data.tar.gz: 6ea2cb19cc04d6888b9aa31567cbcb3a22105f95138090b3b7308e4d4ed96e63fd082a1530de83f88bb440331fedaaa69b3941b563cd3d73068682f1cbb79549
data/CHANGELOG.md CHANGED
@@ -7,6 +7,11 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.4.0] - 2026-04-16
11
+
12
+ ### Added
13
+ - `#with(**overrides)` instance method on generated structs for immutable copy-with-changes
14
+
10
15
  ## [0.3.1] - 2026-04-15
11
16
 
12
17
  ### Changed
@@ -112,7 +117,8 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
112
117
  - Value equality via `#==`
113
118
  - Keyword-only constructor
114
119
 
115
- [Unreleased]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.1...HEAD
120
+ [Unreleased]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.4.0...HEAD
121
+ [0.4.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.1...v0.4.0
116
122
  [0.3.1]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.0...v0.3.1
117
123
  [0.3.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.2.0...v0.3.0
118
124
  [0.2.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.1.0...v0.2.0
data/README.md CHANGED
@@ -141,6 +141,28 @@ alice.age # => 30 (unchanged)
141
141
  older.age # => 31
142
142
  ```
143
143
 
144
+ ### Copy With Changes
145
+
146
+ ```ruby
147
+ require 'philiprehberger/struct_kit'
148
+
149
+ User = Philiprehberger::StructKit.define do
150
+ field :name, String
151
+ field :age, Integer, default: 0
152
+ end
153
+
154
+ alice = User.new(name: 'Alice', age: 30)
155
+ bob = alice.with(name: 'Bob')
156
+
157
+ alice.name # => "Alice" (unchanged)
158
+ bob.name # => "Bob"
159
+ bob.age # => 30 (retained)
160
+
161
+ # Overrides are re-validated through the existing type/validation system:
162
+ alice.with(age: 'oops') # TypeError: age must be Integer, got String
163
+ alice.with(nope: 1) # ArgumentError: unknown keyword: nope
164
+ ```
165
+
144
166
  ### Presence Validation
145
167
 
146
168
  ```ruby
@@ -188,6 +210,7 @@ Define a new struct class. Evaluates the block in DSL context.
188
210
  | `#to_a` | Convert to an array of values in field-declaration order |
189
211
  | `#to_json` | Convert to JSON string |
190
212
  | `#with(**changes)` | Return a new instance with the given fields changed |
213
+ | `#with(**overrides)` | Immutable copy-with: return a new instance with selected fields replaced (re-validated) |
191
214
  | `#deconstruct_keys(keys)` | Pattern matching support |
192
215
  | `#==` | Value equality |
193
216
  | `#inspect` | Human-readable string representation |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module StructKit
5
- VERSION = '0.3.1'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-struct_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Philip Rehberger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-04-15 00:00:00.000000000 Z
11
+ date: 2026-04-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Define data classes with typed fields, default values, validation rules,
14
14
  and pattern matching support. Immutable by default with keyword-only construction,