glob 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +32 -0
- data/lib/glob/map.rb +6 -2
- data/lib/glob/query.rb +5 -1
- data/lib/glob/version.rb +1 -1
- data/test/glob_test.rb +20 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: daa19b4757ede88d7bc2ff99732f6e0a42b33608fbbef748c21c18f73a01538c
|
4
|
+
data.tar.gz: c8ee66c99f7ce11218ff7fc4031ad0a53e8fe7afb9eaa0de8b9220be92c88690
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56d9f2f4ba26236f4ce29c51a806c6a158c5576222ab2ccc7d801423a6be0ae759ef2b8db21f465d03de2f97aac4b2b7de0a21dcc9d35ceaa74397e720783014
|
7
|
+
data.tar.gz: 8ebc481895cc295261e1914b690ccd4b3807419564c833e258a9efccabf8f2ead910e599007e663227821ca7d03ced3dae9dc491608c832f8e0886956dce579a
|
data/CHANGELOG.md
CHANGED
@@ -11,6 +11,14 @@ Prefix your message with one of the following:
|
|
11
11
|
- [Security] in case of vulnerabilities.
|
12
12
|
-->
|
13
13
|
|
14
|
+
## v0.3.1 - 2022-09-01
|
15
|
+
|
16
|
+
- [Fixed] Handle keys with dots properly by using `\\.` as a escape sequence.
|
17
|
+
|
18
|
+
## v0.3.0 - 2022-08-01
|
19
|
+
|
20
|
+
- [Added] Patterns can have groups like in `{a,b}.*`.
|
21
|
+
|
14
22
|
## v0.2.2 - 2022-02-01
|
15
23
|
|
16
24
|
- [Fixed] Properly handle numeric keys.
|
data/README.md
CHANGED
@@ -72,6 +72,38 @@ glob.to_h
|
|
72
72
|
|
73
73
|
Notice that the return result will have symbolized keys.
|
74
74
|
|
75
|
+
If the contains dots, then the result will use `\\.` as the escape sequence.
|
76
|
+
Similarly, you need to escape keys with dots when filtering results.
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
glob = Glob.new(
|
80
|
+
formats: {
|
81
|
+
".txt" => "Text",
|
82
|
+
".json" => "JSON",
|
83
|
+
".rb" => "Ruby"
|
84
|
+
}
|
85
|
+
)
|
86
|
+
|
87
|
+
glob << "*"
|
88
|
+
|
89
|
+
glob.paths
|
90
|
+
#=> ["formats.\\.json", "formats.\\.rb", "formats.\\.txt"]
|
91
|
+
|
92
|
+
glob.to_h
|
93
|
+
#=> {:formats=>{:".json"=>"JSON", :".rb"=>"Ruby", :".txt"=>"Text"}}
|
94
|
+
|
95
|
+
# Remove all existing matchers
|
96
|
+
glob.matchers.clear
|
97
|
+
|
98
|
+
glob << "formats.\\.rb"
|
99
|
+
|
100
|
+
glob.paths
|
101
|
+
#=> ["formats.\\.rb"]
|
102
|
+
|
103
|
+
glob.to_h
|
104
|
+
#=> {:formats=>{:".rb"=>"Ruby"}}
|
105
|
+
```
|
106
|
+
|
75
107
|
## Maintainer
|
76
108
|
|
77
109
|
- [Nando Vieira](https://github.com/fnando)
|
data/lib/glob/map.rb
CHANGED
@@ -13,15 +13,19 @@ module Glob
|
|
13
13
|
|
14
14
|
def call
|
15
15
|
@target
|
16
|
-
.map {|(key, value)| compute(value, key) }
|
16
|
+
.map {|(key, value)| compute(value, escape(key)) }
|
17
17
|
.flatten
|
18
18
|
.sort
|
19
19
|
end
|
20
20
|
|
21
|
+
private def escape(key)
|
22
|
+
key.to_s.gsub(".", "\\.")
|
23
|
+
end
|
24
|
+
|
21
25
|
private def compute(value, path)
|
22
26
|
if value.is_a?(Hash)
|
23
27
|
value.map do |key, other_value|
|
24
|
-
compute(other_value, "#{path}.#{key}")
|
28
|
+
compute(other_value, "#{path}.#{escape(key)}")
|
25
29
|
end
|
26
30
|
else
|
27
31
|
path.to_s
|
data/lib/glob/query.rb
CHANGED
@@ -18,7 +18,7 @@ module Glob
|
|
18
18
|
symbolized_target = SymbolizeKeys.call(@target)
|
19
19
|
|
20
20
|
paths.each_with_object({}) do |path, buffer|
|
21
|
-
segments = path.split(
|
21
|
+
segments = path.split(/(?<!\\)\./).map {|key| unescape(key).to_sym }
|
22
22
|
value = symbolized_target.dig(*segments)
|
23
23
|
set_path_value(segments, buffer, value)
|
24
24
|
end
|
@@ -41,6 +41,10 @@ module Glob
|
|
41
41
|
@map ||= Map.call(@target)
|
42
42
|
end
|
43
43
|
|
44
|
+
private def unescape(key)
|
45
|
+
key.to_s.gsub(/\\\./, ".")
|
46
|
+
end
|
47
|
+
|
44
48
|
private def set_path_value(segments, target, value)
|
45
49
|
while (segment = segments.shift)
|
46
50
|
if segments.empty?
|
data/lib/glob/version.rb
CHANGED
data/test/glob_test.rb
CHANGED
@@ -220,4 +220,24 @@ class GlobTest < Minitest::Test
|
|
220
220
|
|
221
221
|
assert_equal expected, glob.paths
|
222
222
|
end
|
223
|
+
|
224
|
+
test "with keys that contain dots" do
|
225
|
+
data = {
|
226
|
+
"keys.with.dots" => "dots",
|
227
|
+
node: {
|
228
|
+
"more.keys.with.dots" => "more dots"
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
glob = Glob.new(data)
|
233
|
+
|
234
|
+
glob << "*"
|
235
|
+
|
236
|
+
assert_equal %w[keys\\.with\\.dots node.more\\.keys\\.with\\.dots],
|
237
|
+
glob.paths
|
238
|
+
assert_equal Glob::SymbolizeKeys.call(data), glob.to_h
|
239
|
+
|
240
|
+
assert_equal ({node: {"more.keys.with.dots": "more dots"}}),
|
241
|
+
Glob.filter(data, ["node.more\\.keys\\.with\\.dots"])
|
242
|
+
end
|
223
243
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glob
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -152,10 +152,10 @@ metadata:
|
|
152
152
|
rubygems_mfa_required: 'true'
|
153
153
|
homepage_uri: https://github.com/fnando/glob
|
154
154
|
bug_tracker_uri: https://github.com/fnando/glob/issues
|
155
|
-
source_code_uri: https://github.com/fnando/glob/tree/v0.3.
|
156
|
-
changelog_uri: https://github.com/fnando/glob/tree/v0.3.
|
157
|
-
documentation_uri: https://github.com/fnando/glob/tree/v0.3.
|
158
|
-
license_uri: https://github.com/fnando/glob/tree/v0.3.
|
155
|
+
source_code_uri: https://github.com/fnando/glob/tree/v0.3.1
|
156
|
+
changelog_uri: https://github.com/fnando/glob/tree/v0.3.1/CHANGELOG.md
|
157
|
+
documentation_uri: https://github.com/fnando/glob/tree/v0.3.1/README.md
|
158
|
+
license_uri: https://github.com/fnando/glob/tree/v0.3.1/LICENSE.md
|
159
159
|
post_install_message:
|
160
160
|
rdoc_options: []
|
161
161
|
require_paths:
|