philiprehberger-struct_kit 0.3.0 → 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: a0152f7975b6372edce049e3983a3d488a1405514732dc49d0d18c2f650f5cb5
4
- data.tar.gz: 9edcdd291201087f68ee11f08ca400d8fdfaac7403bdf8368ebec4dcee18ffa2
3
+ metadata.gz: 0a50ed52bad42906d2452f7e16fa3713287f263582554a7f8d67ab404a47d65e
4
+ data.tar.gz: a4e55b469fc1e50ca7388f66b309f69d3046a2100b58c50fb88a06c67150799e
5
5
  SHA512:
6
- metadata.gz: 923c971ee52f8e015b593e54f0cbb091522b05f2cd9ab4ef96a8ec980626c4785bddaf1d5ac5bed199d3f6ae2b25d792ed12319eb63cf7f9a0456724a07827c8
7
- data.tar.gz: a24215634ee0dd5302f446821d2142a1e426a81a31c7597936f305a44b59f0a00c25b5481dd3b01ad43e1362f95d477231683e2bc385f00271a1ee2e363f610b
6
+ metadata.gz: 92f45e162b4c8e851bf33345ecc19bdbfd37a171174dd2a76351e98462bb0f44052b079a12651dd935aa46729e7368755c8b0926060e6c51af3411bd8907ed43
7
+ data.tar.gz: 6ea2cb19cc04d6888b9aa31567cbcb3a22105f95138090b3b7308e4d4ed96e63fd082a1530de83f88bb440331fedaaa69b3941b563cd3d73068682f1cbb79549
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ 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
+
15
+ ## [0.3.1] - 2026-04-15
16
+
17
+ ### Changed
18
+ - Normalize README title to `philiprehberger-struct-kit` per readme template
19
+ - Standardize `require` statements to single quotes across README examples
20
+ - Update gemspec `homepage` URL to the hyphenated portfolio slug
21
+
10
22
  ## [0.3.0] - 2026-04-15
11
23
 
12
24
  ### Added
@@ -105,7 +117,9 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
105
117
  - Value equality via `#==`
106
118
  - Keyword-only constructor
107
119
 
108
- [Unreleased]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.0...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
122
+ [0.3.1]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.0...v0.3.1
109
123
  [0.3.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.2.0...v0.3.0
110
124
  [0.2.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.1.0...v0.2.0
111
125
  [0.1.0]: https://github.com/philiprehberger/rb-struct-kit/releases/tag/v0.1.0
data/README.md CHANGED
@@ -15,7 +15,7 @@ Enhanced struct builder with typed fields, defaults, validation, and pattern mat
15
15
  Add to your Gemfile:
16
16
 
17
17
  ```ruby
18
- gem "philiprehberger-struct_kit"
18
+ gem 'philiprehberger-struct_kit'
19
19
  ```
20
20
 
21
21
  Or install directly:
@@ -27,7 +27,7 @@ gem install philiprehberger-struct_kit
27
27
  ## Usage
28
28
 
29
29
  ```ruby
30
- require "philiprehberger/struct_kit"
30
+ require 'philiprehberger/struct_kit'
31
31
 
32
32
  User = Philiprehberger::StructKit.define do
33
33
  field :name, String
@@ -100,7 +100,7 @@ User.from_h({ 'name' => 'Bob', 'age' => 25 }) # string keys OK
100
100
  ### Coercion
101
101
 
102
102
  ```ruby
103
- require "philiprehberger/struct_kit"
103
+ require 'philiprehberger/struct_kit'
104
104
 
105
105
  User = Philiprehberger::StructKit.define do
106
106
  field :age, Integer, coerce: ->(v) { Integer(v) }
@@ -127,7 +127,7 @@ end
127
127
  ### Non-destructive Updates
128
128
 
129
129
  ```ruby
130
- require "philiprehberger/struct_kit"
130
+ require 'philiprehberger/struct_kit'
131
131
 
132
132
  User = Philiprehberger::StructKit.define do
133
133
  field :name, String
@@ -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.0'
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.0
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,