dotkey 1.0.0 → 1.0.1

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: 59465e04fac7799b3ae896136cf7c2e6d756d3638ce4fd4229b1b69968e42821
4
- data.tar.gz: 20ce766129ecf3dab53ada7364949f423ddd2d8f287d1812219de3db733a937e
3
+ metadata.gz: 6f417d3b9361adfee3ad70d0154f47d92b6293bd884dc17b3dff7f7538f8b680
4
+ data.tar.gz: 309553fccb7020530a737ddef1559fbd4db6080aefa0d1209463f972281bdcad
5
5
  SHA512:
6
- metadata.gz: 40abb13a263c3e77daedeb909087115539a66488721272105380f3e33b5c0856c1680ba65f8befadbdeeaf04ea9fca3b73ab0734f9bddcde03e6d48a8f7e729d
7
- data.tar.gz: 17129e2bc6555e2b9abd4010d07d8e299267d62b2a47e71e59f82dc97d10a55dd16480a4cd1ddbcaa068d3d829540e7929687743ba0b195ce84a32325eafa008
6
+ metadata.gz: 39defa17fd3a0384b0b94a33c9b438009b72fae2771ef8f5f967729806f1eb0c1262d912a603eeb340e5995df84cda765e8450f20e956fdc78261b94be8e6b1c
7
+ data.tar.gz: 26ac9660e15c2db59deff29e10a78f777d60ca4231a7db6fa8f5290dbac4730beaccb7fc96afd6c3d479854746c6af5a03095ee775207c38db045a336c306643
data/CHANGELOG.md CHANGED
@@ -1,2 +1,6 @@
1
- ## 1.0.0 [UNRELEASED]
1
+ ## 1.0.1 [2025-05-11]
2
+ - Fixed errors in `get_all` errors when traversing nil values
3
+ - Fixed documentation for `get_all` using examples for `get`
4
+
5
+ ## 1.0.0 [2025-05-10]
2
6
  - Initial release
data/README.md CHANGED
@@ -78,23 +78,23 @@ If any values along the path are `nil`, `nil` is returned. However, trying to tr
78
78
 
79
79
  ```ruby
80
80
  # `b.c` is nil so the result is nil
81
- DotKey.get({b: {}}, "b.c.d") # => nil
81
+ DotKey.get_all({b: {}}, "b.c.d") #=> {"b.c.d" => nil}
82
82
 
83
83
  # `c` is not a valid key for an Array, so an error is raised
84
- DotKey.get({b: []}, "b.c.d") # => raises DotKey::InvalidTypeError
84
+ DotKey.get_all({b: []}, "b.c.d") #=> raises DotKey::InvalidTypeError
85
85
 
86
86
  # `0` is a valid key for an array, but is nil so the result is nil
87
- DotKey.get({b: []}, "b.0.d") # => nil
87
+ DotKey.get_all({b: []}, "b.0.d") #=> {"b.0.d" => nil}
88
88
 
89
89
  # Strings cannot be traversed so an error is raised
90
- DotKey.get({a: "a string"}, "a.b") # => raises DotKey::InvalidTypeError
90
+ DotKey.get_all({a: "a string"}, "a.b") #=> raises DotKey::InvalidTypeError
91
91
  ```
92
92
 
93
- This behaviour can be disabled by specifying the `raise_on_invalid` parameter:
93
+ This behaviour can be disabled by specifying the `raise_on_invalid` parameter.
94
94
 
95
95
  ```ruby
96
- DotKey.get({b: []}, "b.c.d", raise_on_invalid: false) # => nil
97
- DotKey.get({a: "a string"}, "a.b", raise_on_invalid: false) # => nil
96
+ DotKey.get_all({b: []}, "b.c.d", raise_on_invalid: false) #=> {"b.c.d" => nil}
97
+ DotKey.get_all({a: "a string"}, "a.b", raise_on_invalid: false) #=> {"a.b" => nil}
98
98
  ```
99
99
 
100
100
  Missing values are included in the result as `nil` values, but these can be omitted by specifying the `include_missing` parameter:
@@ -96,21 +96,21 @@ class DotKey
96
96
  # an error is raised.
97
97
  #
98
98
  # # `b.c` is nil so the result is nil
99
- # DotKey.get({b: {}}, "b.c.d") #=> nil
99
+ # DotKey.get_all({b: {}}, "b.c.d") #=> {"b.c.d" => nil}
100
100
  #
101
101
  # # `c` is not a valid key for an Array, so an error is raised
102
- # DotKey.get({b: []}, "b.c.d") #=> raises DotKey::InvalidTypeError
102
+ # DotKey.get_all({b: []}, "b.c.d") #=> raises DotKey::InvalidTypeError
103
103
  #
104
104
  # # `0` is a valid key for an array, but is nil so the result is nil
105
- # DotKey.get({b: []}, "b.0.d") #=> nil
105
+ # DotKey.get_all({b: []}, "b.0.d") #=> {"b.0.d" => nil}
106
106
  #
107
107
  # # Strings cannot be traversed so an error is raised
108
- # DotKey.get({a: "a string"}, "a.b") #=> raises DotKey::InvalidTypeError
108
+ # DotKey.get_all({a: "a string"}, "a.b") #=> raises DotKey::InvalidTypeError
109
109
  #
110
110
  # This behaviour can be disabled by specifying the <tt>raise_on_invalid</tt> parameter.
111
111
  #
112
- # DotKey.get({b: []}, "b.c.d", raise_on_invalid: false) #=> nil
113
- # DotKey.get({a: "a string"}, "a.b", raise_on_invalid: false) #=> nil
112
+ # DotKey.get_all({b: []}, "b.c.d", raise_on_invalid: false) #=> {"b.c.d" => nil}
113
+ # DotKey.get_all({a: "a string"}, "a.b", raise_on_invalid: false) #=> {"a.b" => nil}
114
114
  #
115
115
  # Missing values are included in the result as <tt>nil</tt> values, but these can be
116
116
  # omitted by specifying the <tt>include_missing</tt> parameter.
@@ -147,6 +147,10 @@ class DotKey
147
147
  array.each_with_index do |item, index|
148
148
  object["#{key_prefix}#{index}"] = item
149
149
  end
150
+ elsif array.nil?
151
+ if include_missing
152
+ object["#{key_prefix}*"] = nil
153
+ end
150
154
  elsif raise_on_invalid
151
155
  raise InvalidTypeError.new "Expected #{parent_key} to be an Array, but got #{array.class}"
152
156
  elsif include_missing
@@ -160,6 +164,10 @@ class DotKey
160
164
  hash.each do |hash_key, item|
161
165
  object["#{key_prefix}#{hash_key}"] = item
162
166
  end
167
+ elsif hash.nil?
168
+ if include_missing
169
+ object["#{key_prefix}**"] = nil
170
+ end
163
171
  elsif raise_on_invalid
164
172
  raise InvalidTypeError.new "Expected #{parent_key} to be a Hash, but got #{hash.class}"
165
173
  elsif include_missing
@@ -194,6 +202,10 @@ class DotKey
194
202
  object["#{key_prefix}#{key}"] = nil
195
203
  end
196
204
  end
205
+ elsif val.nil?
206
+ if include_missing
207
+ object["#{key_prefix}#{key}"] = nil
208
+ end
197
209
  elsif raise_on_invalid
198
210
  if val.is_a?(Array) && key_as_int == :invalid
199
211
  raise InvalidTypeError.new "Expected #{key} to be an array key for Array #{parent_key}"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dotkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon J
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-10 00:00:00.000000000 Z
11
+ date: 2025-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -80,8 +80,11 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '2.14'
83
- description: A series of utility methods allowing you to easily interact with Ruby
84
- objects using dot notation
83
+ description: DotKey provides an elegant way to read, write, and manipulate deeply
84
+ nested Hashes and Arrays using dot-delimited strings. It supports wildcards for
85
+ pattern matching, custom delimiters, and flexible handling of missing values - making
86
+ it ideal for working with complex data structures, configuration objects, and API
87
+ responses.
85
88
  email: 2857218+mwnciau@users.noreply.github.com
86
89
  executables: []
87
90
  extensions: []
@@ -118,5 +121,5 @@ requirements: []
118
121
  rubygems_version: 3.4.20
119
122
  signing_key:
120
123
  specification_version: 4
121
- summary: Interact with object using dot notation
124
+ summary: Interact with nested Ruby data structures using dot-delimited strings
122
125
  test_files: []