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 +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +23 -0
- data/lib/philiprehberger/struct_kit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0a50ed52bad42906d2452f7e16fa3713287f263582554a7f8d67ab404a47d65e
|
|
4
|
+
data.tar.gz: a4e55b469fc1e50ca7388f66b309f69d3046a2100b58c50fb88a06c67150799e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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.
|
|
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 |
|
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.
|
|
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-
|
|
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,
|