philiprehberger-struct_kit 0.5.0 → 0.6.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 +12 -3
- data/README.md +10 -0
- data/lib/philiprehberger/struct_kit/definition.rb +8 -1
- 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: 68b7bec33faa5c7e50b69e236a0787c370b8303e8024ea4d2a26f6751e3e5850
|
|
4
|
+
data.tar.gz: c04c4c2eea2bbc45a7d12cf8e6b3560b1f75699917c105378e3b67f4c5a44e42
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: baafc26c5ed314e8968fffe950acfdec20de931582a47002ccb26bcba7906caf11add73365f3a637b15fa128be1e4467cbee907b7194fe926d3927a076e1a751
|
|
7
|
+
data.tar.gz: 56cda98ec744f87b058f66f0afa69d3ac7d087a0ba7350662707c12495758b2e4992210cd581fd01f6d79faaa3d2e08063f13e8a6d1377f11a501e8fd8336d03
|
data/CHANGELOG.md
CHANGED
|
@@ -2,11 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this gem will be documented in this file.
|
|
4
4
|
|
|
5
|
-
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.
|
|
6
|
-
and this
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.6.0] - 2026-05-07
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Generated structs gain `#match?(**pattern)` — returns `true` when every key in the pattern matches the struct's value via `===` (case equality). Pairs with `deconstruct_keys` for partial-attribute checks.
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
- CHANGELOG header normalised to reference Keep a Changelog v1.0.0 and "this project adheres" to match every other Ruby gem.
|
|
17
|
+
|
|
10
18
|
## [0.5.0] - 2026-04-18
|
|
11
19
|
|
|
12
20
|
### Added
|
|
@@ -122,7 +130,8 @@ and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
|
|
122
130
|
- Value equality via `#==`
|
|
123
131
|
- Keyword-only constructor
|
|
124
132
|
|
|
125
|
-
[Unreleased]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.
|
|
133
|
+
[Unreleased]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.6.0...HEAD
|
|
134
|
+
[0.6.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.5.0...v0.6.0
|
|
126
135
|
[0.5.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.4.0...v0.5.0
|
|
127
136
|
[0.4.0]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.1...v0.4.0
|
|
128
137
|
[0.3.1]: https://github.com/philiprehberger/rb-struct-kit/compare/v0.3.0...v0.3.1
|
data/README.md
CHANGED
|
@@ -124,6 +124,15 @@ in { role: :user }
|
|
|
124
124
|
end
|
|
125
125
|
```
|
|
126
126
|
|
|
127
|
+
### Pattern-Style Match
|
|
128
|
+
|
|
129
|
+
```ruby
|
|
130
|
+
user = User.new(name: 'Alice', age: 30, role: :user)
|
|
131
|
+
user.match?(role: :user) # => true
|
|
132
|
+
user.match?(age: 18..30) # => true (uses === for case equality)
|
|
133
|
+
user.match?(name: /^A/) # => true
|
|
134
|
+
```
|
|
135
|
+
|
|
127
136
|
### Non-destructive Updates
|
|
128
137
|
|
|
129
138
|
```ruby
|
|
@@ -230,6 +239,7 @@ Define a new struct class. Evaluates the block in DSL context.
|
|
|
230
239
|
| `#with(**changes)` | Return a new instance with the given fields changed |
|
|
231
240
|
| `#with(**overrides)` | Immutable copy-with: return a new instance with selected fields replaced (re-validated) |
|
|
232
241
|
| `#deconstruct_keys(keys)` | Pattern matching support |
|
|
242
|
+
| `#match?(**pattern)` | Returns true when every key in pattern matches via `===` |
|
|
233
243
|
| `#==` | Value equality |
|
|
234
244
|
| `#inspect` | Human-readable string representation |
|
|
235
245
|
|
|
@@ -25,7 +25,7 @@ module Philiprehberger
|
|
|
25
25
|
@validations[field_name] << block if block
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
def build # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
|
28
|
+
def build # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
29
29
|
fields = @fields.dup
|
|
30
30
|
mutable = @mutable
|
|
31
31
|
|
|
@@ -123,6 +123,13 @@ module Philiprehberger
|
|
|
123
123
|
keys ? h.slice(*keys) : h
|
|
124
124
|
end
|
|
125
125
|
|
|
126
|
+
define_method(:match?) do |**pattern|
|
|
127
|
+
unknown = pattern.keys - self.class._fields.keys
|
|
128
|
+
raise ArgumentError, "unknown keyword: #{unknown.first}" unless unknown.empty?
|
|
129
|
+
|
|
130
|
+
pattern.all? { |k, v| v === instance_variable_get(:"@#{k}") } # rubocop:disable Style/CaseEquality
|
|
131
|
+
end
|
|
132
|
+
|
|
126
133
|
define_method(:==) do |other|
|
|
127
134
|
other.is_a?(self.class) && to_h == other.to_h
|
|
128
135
|
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.
|
|
4
|
+
version: 0.6.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-
|
|
11
|
+
date: 2026-05-07 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,
|