philiprehberger-ini_parser 0.2.1 → 0.3.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 -0
- data/README.md +23 -0
- data/lib/philiprehberger/ini_parser/version.rb +1 -1
- data/lib/philiprehberger/ini_parser.rb +51 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1cf47dfaf9c22a83ad5c659ed8264686b292c1f4250a5074405e8a87fd240ea5
|
|
4
|
+
data.tar.gz: f42efc500aa01b7e54472336039616897c16777392c70ff600d679c26966c9ce
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 621e14af7bb9aa33cc22c2db58485d80f0b18c17d5d0905cc20bda7107e411a2aeef502028673e4ec8ada389736d04ab608e7b8d19f7eab3bb34e16322781e33
|
|
7
|
+
data.tar.gz: ec971c74c15edb83fb355ced07fe7200e19a735e0fffb81b7de82f0fa8b7127891fa2e93a4819ca7bda8017cf80d217e4d28cf77a25749a5dc559ed182597c9a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-04-09
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `valid?(string)` method to check INI syntax without raising exceptions
|
|
14
|
+
- `get(hash, path, default: nil)` for dot-path access to nested config values
|
|
15
|
+
- `set(hash, path, value)` for dot-path mutation of nested config values
|
|
16
|
+
|
|
10
17
|
## [0.2.1] - 2026-03-31
|
|
11
18
|
|
|
12
19
|
### Changed
|
data/README.md
CHANGED
|
@@ -115,6 +115,26 @@ diff[:removed] # => {"section" => {"old_key" => "value"}}
|
|
|
115
115
|
diff[:changed] # => {"section" => {"key" => {from: "old", to: "new"}}}
|
|
116
116
|
```
|
|
117
117
|
|
|
118
|
+
### Dot-Path Access
|
|
119
|
+
|
|
120
|
+
Retrieve or set nested values using dot-separated paths:
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
config = Philiprehberger::IniParser.load("config.ini")
|
|
124
|
+
|
|
125
|
+
Philiprehberger::IniParser.get(config, "database.host") # => "localhost"
|
|
126
|
+
Philiprehberger::IniParser.get(config, "database.missing", default: 3306) # => 3306
|
|
127
|
+
|
|
128
|
+
Philiprehberger::IniParser.set(config, "database.port", 5433)
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Validation
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
Philiprehberger::IniParser.valid?("[section]\nkey = value") # => true
|
|
135
|
+
Philiprehberger::IniParser.valid?("not valid ini") # => false
|
|
136
|
+
```
|
|
137
|
+
|
|
118
138
|
### Listing Sections
|
|
119
139
|
|
|
120
140
|
```ruby
|
|
@@ -132,6 +152,9 @@ sections = Philiprehberger::IniParser.sections("config.ini")
|
|
|
132
152
|
| `IniParser.save(hash, path)` | Write a Hash to an INI file |
|
|
133
153
|
| `IniParser.merge(base, override)` | Deep merge two INI configurations |
|
|
134
154
|
| `IniParser.diff(a, b)` | Compare two parsed hashes and return added, removed, and changed keys |
|
|
155
|
+
| `IniParser.valid?(string)` | Check if an INI string is syntactically valid |
|
|
156
|
+
| `IniParser.get(hash, path, default: nil)` | Retrieve a value using a dot-separated path |
|
|
157
|
+
| `IniParser.set(hash, path, value)` | Set a value using a dot-separated path |
|
|
135
158
|
| `IniParser.sections(string_or_path)` | Extract section names without fully parsing values |
|
|
136
159
|
|
|
137
160
|
## Development
|
|
@@ -95,6 +95,57 @@ module Philiprehberger
|
|
|
95
95
|
result
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
+
# Check whether an INI string is syntactically valid.
|
|
99
|
+
#
|
|
100
|
+
# @param string [String] INI content
|
|
101
|
+
# @return [Boolean] true if the content parses without errors
|
|
102
|
+
def self.valid?(string)
|
|
103
|
+
parse(string)
|
|
104
|
+
true
|
|
105
|
+
rescue ParseError
|
|
106
|
+
false
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Retrieve a value from a parsed hash using a dot-separated path.
|
|
110
|
+
#
|
|
111
|
+
# @param hash [Hash] parsed configuration
|
|
112
|
+
# @param path [String] dot-separated key path (e.g. "database.host")
|
|
113
|
+
# @param default [Object] value to return if the path does not exist
|
|
114
|
+
# @return [Object] the value at the path, or the default
|
|
115
|
+
def self.get(hash, path, default: nil)
|
|
116
|
+
keys = path.to_s.split('.')
|
|
117
|
+
current = hash
|
|
118
|
+
|
|
119
|
+
keys.each do |key|
|
|
120
|
+
return default unless current.is_a?(Hash) && current.key?(key)
|
|
121
|
+
|
|
122
|
+
current = current[key]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
current
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# Set a value in a parsed hash using a dot-separated path.
|
|
129
|
+
#
|
|
130
|
+
# Creates intermediate section hashes as needed.
|
|
131
|
+
#
|
|
132
|
+
# @param hash [Hash] parsed configuration (mutated in place)
|
|
133
|
+
# @param path [String] dot-separated key path (e.g. "database.host")
|
|
134
|
+
# @param value [Object] the value to set
|
|
135
|
+
# @return [Object] the value that was set
|
|
136
|
+
def self.set(hash, path, value)
|
|
137
|
+
keys = path.to_s.split('.')
|
|
138
|
+
last = keys.pop
|
|
139
|
+
current = hash
|
|
140
|
+
|
|
141
|
+
keys.each do |key|
|
|
142
|
+
current[key] = {} unless current[key].is_a?(Hash)
|
|
143
|
+
current = current[key]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
current[last] = value
|
|
147
|
+
end
|
|
148
|
+
|
|
98
149
|
# Extract section names from INI content without fully parsing values.
|
|
99
150
|
#
|
|
100
151
|
# @param string_or_path [String] INI content string or file path
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-ini_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.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-04-10 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Parse and generate INI configuration files with sections, inline comments,
|
|
14
14
|
multiline values, escape sequences, quoted values, and automatic type coercion for
|
|
@@ -26,11 +26,11 @@ files:
|
|
|
26
26
|
- lib/philiprehberger/ini_parser/parser.rb
|
|
27
27
|
- lib/philiprehberger/ini_parser/serializer.rb
|
|
28
28
|
- lib/philiprehberger/ini_parser/version.rb
|
|
29
|
-
homepage: https://
|
|
29
|
+
homepage: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-ini_parser
|
|
30
30
|
licenses:
|
|
31
31
|
- MIT
|
|
32
32
|
metadata:
|
|
33
|
-
homepage_uri: https://
|
|
33
|
+
homepage_uri: https://philiprehberger.com/open-source-packages/ruby/philiprehberger-ini_parser
|
|
34
34
|
source_code_uri: https://github.com/philiprehberger/rb-ini-parser
|
|
35
35
|
changelog_uri: https://github.com/philiprehberger/rb-ini-parser/blob/main/CHANGELOG.md
|
|
36
36
|
bug_tracker_uri: https://github.com/philiprehberger/rb-ini-parser/issues
|