philiprehberger-toml_kit 0.2.4 → 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: f26a997551860b6225437012c11bee16dd81f8b20be5daf280d87e10b3f4b842
4
- data.tar.gz: 9bf2e377233636b4bf619b0bcacec17d0fa2638a46d329230eb1c2ca9af35b3b
3
+ metadata.gz: 8cdca57335aa874bbc1ed3f637df91a738bddc6316b82df101925c0ed383fc37
4
+ data.tar.gz: 6edfe631dd620f5def0c1477db9a14a2bed6eba13810a9ce03d3548abba062eb
5
5
  SHA512:
6
- metadata.gz: 328d22b2d58478a2890f3e6b6470cfb6c188ff96fc0db22570422b4daecf362745659fe34a2a08a6fa6dd04208b98c67d5580811729cb6560cd7a484fa244850
7
- data.tar.gz: 8cc9518b64da7aedad615f29cbb480b8778a23d9461ef1efbfe36431b79793aef03625fbe0d24459b46a4ec5df52991d6eaeacc0da6ee984d4637266f47abe01
6
+ metadata.gz: 56b547d9009966fc988cc954fca8a3a40b35057306b936db0a487f275a3b97bae6e959f08134c08f40198896a335bfde902484e9c026e09c7a5116cf39d5a8a4
7
+ data.tar.gz: 745fdff008a2c06306ccc64567119401b12578369783fe6afcf39003ef0d4604a89ff3dc2279d765eb82e68a720cdf3d888ca502379bcab94cd8682508a5f5f6
data/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ 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-30
11
+
12
+ ### Added
13
+ - `TomlKit.set(data, path, value)` — set a nested value at a dot-path, creating intermediate hashes as needed (mirrors `TomlKit.query`)
14
+ - `TomlKit.delete(data, path)` — delete a nested key by dot-path; returns the removed value or `nil`
15
+ - `TomlKit.exists?(data, path)` — check whether a dot-path resolves to a value
16
+
17
+ ## [0.3.0] - 2026-04-15
18
+
19
+ ### Added
20
+ - `TomlKit.valid?(string)` predicate for checking whether a string parses as TOML without raising
21
+
10
22
  ## [0.2.4] - 2026-04-09
11
23
 
12
24
  ### Fixed
data/README.md CHANGED
@@ -56,6 +56,15 @@ config["database"]["host"] # => "localhost"
56
56
  config["servers"][0]["name"] # => "alpha"
57
57
  ```
58
58
 
59
+ ### Validity Check
60
+
61
+ Check whether a string is valid TOML without raising:
62
+
63
+ ```ruby
64
+ Philiprehberger::TomlKit.valid?('key = "value"') # => true
65
+ Philiprehberger::TomlKit.valid?('key = [broken') # => false
66
+ ```
67
+
59
68
  ### Loading Files
60
69
 
61
70
  ```ruby
@@ -194,10 +203,10 @@ Philiprehberger::TomlKit.query(data, "servers[0].name")
194
203
  Philiprehberger::TomlKit.query(data, "missing.path", default: "N/A")
195
204
  # => "N/A"
196
205
 
197
- # Additional Query methods
198
- Philiprehberger::TomlKit::Query.set(data, "database.timeout", 30)
199
- Philiprehberger::TomlKit::Query.exists?(data, "database.host") # => true
200
- Philiprehberger::TomlKit::Query.delete(data, "database.timeout") # => 30
206
+ # Top-level mutators (mirror TomlKit.query)
207
+ Philiprehberger::TomlKit.set(data, "database.timeout", 30)
208
+ Philiprehberger::TomlKit.exists?(data, "database.host") # => true
209
+ Philiprehberger::TomlKit.delete(data, "database.timeout") # => 30
201
210
  ```
202
211
 
203
212
  ### Type Coercion Hooks
@@ -253,11 +262,15 @@ Philiprehberger::TomlKit::Diff.identical?(old_config, new_config)
253
262
  | Method | Description |
254
263
  |--------|-------------|
255
264
  | `TomlKit.parse(string)` | Parse a TOML string into a Hash |
265
+ | `TomlKit.valid?(string)` | Return `true` if the string parses as valid TOML |
256
266
  | `TomlKit.load(path)` | Parse a TOML file into a Hash |
257
267
  | `TomlKit.dump(hash)` | Serialize a Hash to a TOML string |
258
268
  | `TomlKit.save(hash, path)` | Write a Hash as a TOML file |
259
269
  | `TomlKit.parse_with_comments(string)` | Parse TOML preserving comments, returns `CommentDocument` |
260
270
  | `TomlKit.query(data, path, default:)` | Dot-path access into nested hashes |
271
+ | `TomlKit.set(data, path, value)` | Set a nested value by dot-path; creates intermediate hashes as needed |
272
+ | `TomlKit.delete(data, path)` | Delete a nested key by dot-path; returns the removed value or `nil` |
273
+ | `TomlKit.exists?(data, path)` | Check whether a dot-path resolves to a value |
261
274
  | `TomlKit.merge(left, right, strategy:)` | Deep merge two hashes with conflict resolution |
262
275
  | `TomlKit.diff(left, right)` | Compare two hashes, returns array of `Diff::Change` |
263
276
  | `Schema.new(properties)` | Create a schema for validation |
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Philiprehberger
4
4
  module TomlKit
5
- VERSION = '0.2.4'
5
+ VERSION = '0.4.0'
6
6
  end
7
7
  end
@@ -29,6 +29,17 @@ module Philiprehberger
29
29
  Parser.new.parse(string)
30
30
  end
31
31
 
32
+ # Check whether a string parses as valid TOML without raising.
33
+ #
34
+ # @param string [String] TOML document
35
+ # @return [Boolean] true if the string is valid TOML
36
+ def self.valid?(string)
37
+ parse(string)
38
+ true
39
+ rescue ParseError
40
+ false
41
+ end
42
+
32
43
  # Parse a TOML file into a Ruby Hash.
33
44
  #
34
45
  # @param path [String] path to a TOML file
@@ -74,6 +85,36 @@ module Philiprehberger
74
85
  Query.get(data, path, default: default)
75
86
  end
76
87
 
88
+ # Set a nested value using a dot-path. Creates intermediate hashes/arrays
89
+ # as needed and mutates `data` in place. Returns the value that was set.
90
+ #
91
+ # @param data [Hash] target hash
92
+ # @param path [String] dot-separated path (e.g., "database.host")
93
+ # @param value [Object] the value to set
94
+ # @return [Object] the value that was set
95
+ def self.set(data, path, value)
96
+ Query.set(data, path, value)
97
+ end
98
+
99
+ # Delete a value at the given dot-path. Returns the removed value or `nil`
100
+ # if the path did not resolve.
101
+ #
102
+ # @param data [Hash] target hash
103
+ # @param path [String] dot-separated path
104
+ # @return [Object, nil] the removed value, or nil
105
+ def self.delete(data, path)
106
+ Query.delete(data, path)
107
+ end
108
+
109
+ # Check whether a value exists at the given dot-path.
110
+ #
111
+ # @param data [Hash] target hash
112
+ # @param path [String] dot-separated path
113
+ # @return [Boolean]
114
+ def self.exists?(data, path)
115
+ Query.exists?(data, path)
116
+ end
117
+
77
118
  # Deep merge two TOML hashes.
78
119
  #
79
120
  # @param left [Hash] base hash
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philiprehberger-toml_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
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-09 00:00:00.000000000 Z
11
+ date: 2026-05-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Parse and generate TOML v1.0 documents with full type support including
14
14
  datetimes, inline tables, and array of tables. Zero dependencies.