dense 1.1.6 → 1.2.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 +5 -5
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +1 -1
- data/Makefile +4 -4
- data/README.md +27 -2
- data/dense.gemspec +3 -2
- data/lib/dense/methods.rb +11 -0
- data/lib/dense/parser.rb +1 -0
- data/lib/dense/path.rb +13 -0
- data/lib/dense.rb +2 -1
- metadata +9 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 1daec03bdadb5e3cd1fead3b1021067b510a6a4904e70740287bf31b1ba95f8a
|
|
4
|
+
data.tar.gz: 702a1847c4b6f5aa199cf8e94ca57c06ffb110fbed20492d904ff980f9583c12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fa3c85bae7c996f9ad192dcc2630e3f4d86dcea7498cbff38bacac4af5794cd10e8edf4d5ee68f1309ce63a127448cf1c54af86f6eac8022adfa8b065bc03873
|
|
7
|
+
data.tar.gz: 306798c70dd690aa39d1e775900ba3073c4c9efcbbc248d1e87085c1644887f8bb4492d509c463e44f518b1f0cc2e05146d83f323469c3c0edc2bc697ac3f3c3
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
# dense
|
|
3
3
|
|
|
4
4
|
|
|
5
|
+
## dense 1.2.0 released 2026-02-07
|
|
6
|
+
|
|
7
|
+
* Introduce Dense.list(coll, '..author'), like .get but always returns an array
|
|
8
|
+
* Introduce Dense.paths(coll, '..author')
|
|
9
|
+
* Stop fooling around and stick to https://semver.org
|
|
10
|
+
|
|
11
|
+
|
|
5
12
|
## dense 1.1.6 released 2018-12-24 (Merry Christmas!)
|
|
6
13
|
|
|
7
14
|
* Interpret "replies.0_1_2" as `[ "replies", "0_1_2" ]` not `[ "replies", 0 ]`
|
data/LICENSE.txt
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
Copyright (c) 2017-
|
|
2
|
+
Copyright (c) 2017-2026, John Mettraux, jmettraux+flor@gmail.com
|
|
3
3
|
|
|
4
4
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
5
|
of this software and associated documentation files (the "Software"), to deal
|
data/Makefile
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
## gem tasks ##
|
|
3
3
|
|
|
4
|
-
NAME
|
|
5
|
-
|
|
6
|
-
VERSION
|
|
7
|
-
|
|
4
|
+
NAME != \
|
|
5
|
+
ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name"
|
|
6
|
+
VERSION != \
|
|
7
|
+
ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version"
|
|
8
8
|
|
|
9
9
|
count_lines:
|
|
10
10
|
find lib -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
|
data/README.md
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
# dense
|
|
3
3
|
|
|
4
|
-
[](http://travis-ci.org/floraison/dense)
|
|
5
4
|
[](http://badge.fury.io/rb/dense)
|
|
6
5
|
|
|
7
6
|
Fetching deep in a dense structure. A kind of bastard of [JSONPath](http://goessner.net/articles/JsonPath/).
|
|
@@ -128,7 +127,7 @@ Dense.fetch({ 'a' => [] }, 'a.k.b')
|
|
|
128
127
|
# TypeError: no key "k" for Array at "a"
|
|
129
128
|
```
|
|
130
129
|
|
|
131
|
-
See KeyError and TypeError below for more details.
|
|
130
|
+
See `KeyError` and `TypeError` below for more details.
|
|
132
131
|
|
|
133
132
|
`Dense.fetch(collection, path)` raises when it doesn't find, while `Dense.get(collection, path)` returns `nil`.
|
|
134
133
|
|
|
@@ -318,6 +317,32 @@ c
|
|
|
318
317
|
# => { 'h' => { 'a' => [ 1, 2, 5 ] } }
|
|
319
318
|
```
|
|
320
319
|
|
|
320
|
+
|
|
321
|
+
### `Dense.list(collection, path)`
|
|
322
|
+
|
|
323
|
+
Like `Dense.get` but returns an array of match. Returns an empty array if no match.
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
### `Dense.paths(collection, path)`
|
|
327
|
+
|
|
328
|
+
Given a "glob" path, returns the list of paths to the matching leaves (or an empty array instead).
|
|
329
|
+
|
|
330
|
+
```ruby
|
|
331
|
+
Dense.paths(data, '..author')
|
|
332
|
+
# => %w[
|
|
333
|
+
# store.book.0.author store.book.1.author store.book.2.author
|
|
334
|
+
# store.book.3.author ]
|
|
335
|
+
|
|
336
|
+
Dense.paths(data, '..price')
|
|
337
|
+
# => %w[
|
|
338
|
+
# store.book.0.price store.book.1.price store.book.2.price
|
|
339
|
+
# store.book.3.price store.bicycle.price ]
|
|
340
|
+
|
|
341
|
+
Dense.paths(data, '..nada')
|
|
342
|
+
# => []
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
|
|
321
346
|
### KeyError and TypeError
|
|
322
347
|
|
|
323
348
|
Dense might raise instances of `KeyError` and `TypeError`. Those instances have extra `#full_path` and `#miss` methods.
|
data/dense.gemspec
CHANGED
|
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
|
10
10
|
s.platform = Gem::Platform::RUBY
|
|
11
11
|
s.authors = [ 'John Mettraux' ]
|
|
12
12
|
s.email = [ 'jmettraux+flor@gmail.com' ]
|
|
13
|
-
s.homepage = '
|
|
13
|
+
s.homepage = 'https://github.com/floraison/dense'
|
|
14
14
|
s.license = 'MIT'
|
|
15
15
|
s.summary = 'fetching deep in a dense structure'
|
|
16
16
|
|
|
@@ -29,7 +29,8 @@ Fetching deep in a dense structure. A kind of bastard of JSONPath.
|
|
|
29
29
|
|
|
30
30
|
s.add_runtime_dependency 'raabro', '~> 1.1', '>= 1.1.5'
|
|
31
31
|
|
|
32
|
-
s.add_development_dependency 'rspec', '~> 3.7'
|
|
32
|
+
#s.add_development_dependency 'rspec', '~> 3.7'
|
|
33
|
+
s.add_development_dependency 'probatio'
|
|
33
34
|
|
|
34
35
|
s.require_path = 'lib'
|
|
35
36
|
end
|
data/lib/dense/methods.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
|
|
2
3
|
module Dense; class << self
|
|
3
4
|
|
|
@@ -112,6 +113,16 @@ module Dense; class << self
|
|
|
112
113
|
Dense::Path.make(path).gather(o)
|
|
113
114
|
end
|
|
114
115
|
|
|
116
|
+
def paths(o, glob)
|
|
117
|
+
|
|
118
|
+
Dense::Path.make(glob).enumerate(o)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def list(o, path)
|
|
122
|
+
|
|
123
|
+
Dense::Path.make(path).list(o)
|
|
124
|
+
end
|
|
125
|
+
|
|
115
126
|
protected
|
|
116
127
|
|
|
117
128
|
def key_matches_collection?(k, c)
|
data/lib/dense/parser.rb
CHANGED
data/lib/dense/path.rb
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
1
2
|
|
|
2
3
|
class Dense::Path
|
|
3
4
|
|
|
@@ -165,6 +166,18 @@ class Dense::Path
|
|
|
165
166
|
.values
|
|
166
167
|
end
|
|
167
168
|
|
|
169
|
+
def enumerate(data)
|
|
170
|
+
|
|
171
|
+
_gather(0, [], nil, data, @path, [])
|
|
172
|
+
.collect { |_, p0, _, k| p0.dup.concat([ k ]).map(&:to_s).join('.') }
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
def list(data)
|
|
176
|
+
|
|
177
|
+
_gather(0, [], nil, data, @path, [])
|
|
178
|
+
.collect { |_, _, coll, k| coll[k] }
|
|
179
|
+
end
|
|
180
|
+
|
|
168
181
|
protected
|
|
169
182
|
|
|
170
183
|
def _keys(o)
|
data/lib/dense.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: dense
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- John Mettraux
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: raabro
|
|
@@ -31,19 +30,19 @@ dependencies:
|
|
|
31
30
|
- !ruby/object:Gem::Version
|
|
32
31
|
version: 1.1.5
|
|
33
32
|
- !ruby/object:Gem::Dependency
|
|
34
|
-
name:
|
|
33
|
+
name: probatio
|
|
35
34
|
requirement: !ruby/object:Gem::Requirement
|
|
36
35
|
requirements:
|
|
37
|
-
- - "
|
|
36
|
+
- - ">="
|
|
38
37
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: '
|
|
38
|
+
version: '0'
|
|
40
39
|
type: :development
|
|
41
40
|
prerelease: false
|
|
42
41
|
version_requirements: !ruby/object:Gem::Requirement
|
|
43
42
|
requirements:
|
|
44
|
-
- - "
|
|
43
|
+
- - ">="
|
|
45
44
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: '
|
|
45
|
+
version: '0'
|
|
47
46
|
description: Fetching deep in a dense structure. A kind of bastard of JSONPath.
|
|
48
47
|
email:
|
|
49
48
|
- jmettraux+flor@gmail.com
|
|
@@ -60,11 +59,10 @@ files:
|
|
|
60
59
|
- lib/dense/methods.rb
|
|
61
60
|
- lib/dense/parser.rb
|
|
62
61
|
- lib/dense/path.rb
|
|
63
|
-
homepage:
|
|
62
|
+
homepage: https://github.com/floraison/dense
|
|
64
63
|
licenses:
|
|
65
64
|
- MIT
|
|
66
65
|
metadata: {}
|
|
67
|
-
post_install_message:
|
|
68
66
|
rdoc_options: []
|
|
69
67
|
require_paths:
|
|
70
68
|
- lib
|
|
@@ -79,9 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
79
77
|
- !ruby/object:Gem::Version
|
|
80
78
|
version: '0'
|
|
81
79
|
requirements: []
|
|
82
|
-
|
|
83
|
-
rubygems_version: 2.6.14.3
|
|
84
|
-
signing_key:
|
|
80
|
+
rubygems_version: 3.6.9
|
|
85
81
|
specification_version: 4
|
|
86
82
|
summary: fetching deep in a dense structure
|
|
87
83
|
test_files: []
|