philiprehberger-typed_hash 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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +15 -0
- data/lib/philiprehberger/typed_hash/instance.rb +8 -0
- data/lib/philiprehberger/typed_hash/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: 5c4c963576e9085e3cf743b148ad65784bc8e5410eabaad510b566c2fb1ef1db
|
|
4
|
+
data.tar.gz: b2a49571ca3b4b110dac6f5ad2c24e0e94729f8d382cc88fee74a2f91c14fa72
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a8e1b4dde804b5f6b6de2f0af805c9228241ed1786019501366d0cffcb574d8172a42fbe3608f65d1d4bd6f95d11864da42222ffdf8d73959c1103abbf962f9
|
|
7
|
+
data.tar.gz: 7a2053901a18e3d8c2bd5cbe08a6832236364b536c930153afcc00feb65b2c1c5e0d2338cfcafe18e2722c9c3e11099db5f5f5908a4b7eb340bed96b85d2b3a4
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.4.0] - 2026-04-29
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Instance#key?(key)` Hash-like membership predicate accepting both Symbol and String keys
|
|
14
|
+
|
|
10
15
|
## [0.3.0] - 2026-04-17
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -142,6 +142,20 @@ updated = base.merge(age: 30)
|
|
|
142
142
|
updated[:age] # => 30
|
|
143
143
|
```
|
|
144
144
|
|
|
145
|
+
### Key Membership
|
|
146
|
+
|
|
147
|
+
```ruby
|
|
148
|
+
schema = Philiprehberger::TypedHash::Schema.new
|
|
149
|
+
schema.key(:name, String)
|
|
150
|
+
schema.key(:age, Integer, optional: true)
|
|
151
|
+
|
|
152
|
+
instance = schema.new(name: 'Alice')
|
|
153
|
+
instance.key?(:name) # => true
|
|
154
|
+
instance.key?('name') # => true (string form works)
|
|
155
|
+
instance.key?(:age) # => false
|
|
156
|
+
instance.key?(:foo) # => false
|
|
157
|
+
```
|
|
158
|
+
|
|
145
159
|
### Schema introspection
|
|
146
160
|
|
|
147
161
|
```ruby
|
|
@@ -184,6 +198,7 @@ included.
|
|
|
184
198
|
|--------|-------------|
|
|
185
199
|
| `#[key]` | Access a value by key |
|
|
186
200
|
| `#[key] = value` | Set a value by key (raises if frozen) |
|
|
201
|
+
| `#key?(key)` | True when `key` is present in the instance data (accepts Symbol or String) |
|
|
187
202
|
| `#valid?` | Check if the instance passes validation |
|
|
188
203
|
| `#errors` | Return validation error messages |
|
|
189
204
|
| `#to_h` | Convert to a plain hash |
|
|
@@ -33,6 +33,14 @@ module Philiprehberger
|
|
|
33
33
|
@data[key] = value
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
+
# Hash-like membership predicate.
|
|
37
|
+
#
|
|
38
|
+
# @param key [Symbol, String] key name
|
|
39
|
+
# @return [Boolean]
|
|
40
|
+
def key?(key)
|
|
41
|
+
@data.key?(key.to_sym)
|
|
42
|
+
end
|
|
43
|
+
|
|
36
44
|
# Check if the instance is valid
|
|
37
45
|
#
|
|
38
46
|
# @return [Boolean] true if no validation errors
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-typed_hash
|
|
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-29 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Define typed hash schemas with per-key type declarations, optional coercion
|
|
14
14
|
functions, default values, strict mode for unknown keys, nested schemas, pick/omit,
|