dense 1.1.6 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 98c2df19e83fe3baf42a83e25dc86a89da6559a5
4
- data.tar.gz: 6ac12307afce7a347cc449e4172ef8036e2883a4
2
+ SHA256:
3
+ metadata.gz: 6b0817224995549d7781d408ed728ce6c5da65e68a7ea0e3343af9be1c384ee3
4
+ data.tar.gz: 7b497011f2f93abe5071d525cfd7726063890510540833a5f21457c9b391964c
5
5
  SHA512:
6
- metadata.gz: 02b601a07946bcae9bd79167aab71e97d39b645abe97813871a4f6e06bd2cc5a72b73058b1a85e7e855f69546e709c289cd5e9df6510a7558661230638a0c02c
7
- data.tar.gz: d1c63c70024f8b7a0b702a203fe1007c65ee4ef28a2d9880b94c150214442bc1a8275a7c3af6ce6271f8a8b9af039d7cfa978400c6639507789bd56e19acae66
6
+ metadata.gz: 2f79ad03555da0dda0bacf23a06ce5daf3b997b24ef49813968a20b6208c61fcc0e5e740a0b0757d903ac8f0fc4d593fbe6d3f28a39de452d221aee2c27580a8
7
+ data.tar.gz: 799f68b5650b88b79ec1d070c3c054d72cccf85300f1864529a36fcc1a5c8fce2a22e6cc861edf60d5d085d8266bff5322408440fcf599829c33829f80bd74a0
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
  # dense
3
3
 
4
4
 
5
+ ## dense 1.3.0 released 2026-07-31
6
+
7
+ * Introduce Dense.dig_deep(coll, '..key') and .dig_wide(coll, '..key')
8
+
9
+
10
+ ## dense 1.2.0 released 2026-02-07
11
+
12
+ * Introduce Dense.list(coll, '..author'), like .get but always returns an array
13
+ * Introduce Dense.paths(coll, '..author')
14
+ * Stop fooling around and stick to https://semver.org
15
+
16
+
5
17
  ## dense 1.1.6 released 2018-12-24 (Merry Christmas!)
6
18
 
7
19
  * 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-2018, John Mettraux, jmettraux+flor@gmail.com
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
- $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.name")
6
- VERSION = \
7
- $(shell ruby -e "s = eval(File.read(Dir['*.gemspec'][0])); puts s.version")
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
- [![Build Status](https://secure.travis-ci.org/floraison/dense.svg)](http://travis-ci.org/floraison/dense)
5
4
  [![Gem Version](https://badge.fury.io/rb/dense.svg)](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,56 @@ 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
+ ### `Dense.dig_deep(collection, glob)` and `Dense.dig_wide(collection, glob)`
346
+
347
+ Using `.path` underneath, returns the first matching with a deep or wide path.
348
+
349
+ ```ruby
350
+ Dense.dig_deep(data, '..janitor')
351
+ # => nil
352
+ Dense.dig_deep(data, '..author')
353
+ # => 'Nigel Rees'
354
+ Dense.dig_deep(data, 'store..author')
355
+ # => 'Nigel Rees'
356
+ Dense.dig_deep(data, '..price')
357
+ # => 19.95
358
+
359
+ Dense.dig_deep(data, '..janitor')
360
+ # => nil
361
+ Dense.dig_deep(data, '..author')
362
+ # => 'Nigel Rees'
363
+ Dense.dig_deep(data, 'store..author')
364
+ # => 'Nigel Rees'
365
+ Dense.dig_deep(data, '..price')
366
+ # => 8.95
367
+ ```
368
+
369
+
321
370
  ### KeyError and TypeError
322
371
 
323
372
  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 = 'http://github.com/floraison/dense'
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', '~> 1.6'
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,38 @@ 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
+
126
+ def dig_deep(o, glob)
127
+
128
+ pa = Dense::Path.make(glob).enumerate(o)
129
+ .inject([ 0, nil ]) { |a, pa|
130
+ pac = pa.count('.')
131
+ pac > a[0] ? [ pac, pa ] : a }
132
+ .last
133
+
134
+ pa ? get(o, pa) : nil
135
+ end
136
+
137
+ def dig_wide(o, glob)
138
+
139
+ pa = Dense::Path.make(glob).enumerate(o)
140
+ .inject([ 9_999_999_999, nil ]) { |a, pa|
141
+ pac = pa.count('.')
142
+ pac < a[0] ? [ pac, pa ] : a }
143
+ .last
144
+
145
+ pa ? get(o, pa) : nil
146
+ end
147
+
115
148
  protected
116
149
 
117
150
  def key_matches_collection?(k, c)
data/lib/dense/parser.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Dense::Path::Parser include ::Raabro
3
4
 
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
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
1
2
 
2
3
  module Dense
3
4
 
4
- VERSION = '1.1.6'
5
+ VERSION = '1.3.0'.freeze
5
6
  end
6
7
 
7
8
  require 'raabro'
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.1.6
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2018-12-23 00:00:00.000000000 Z
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: rspec
33
+ name: probatio
35
34
  requirement: !ruby/object:Gem::Requirement
36
35
  requirements:
37
36
  - - "~>"
38
37
  - !ruby/object:Gem::Version
39
- version: '3.7'
38
+ version: '1.6'
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: '3.7'
45
+ version: '1.6'
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: http://github.com/floraison/dense
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
- rubyforge_project:
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: []