dense 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 24371919775ff81e60eb86f0e9bae21a13a4cd4458e14a3584b05b7a16e7937b
4
- data.tar.gz: '085c7f5db832b45f4c4f0127ad224d4dfa15402b444b5312274f54ac055825d3'
2
+ SHA1:
3
+ metadata.gz: e2d5a14e2829cb3ff312c8ab8bf9647e341e464a
4
+ data.tar.gz: c352a513f49d9fff4b7fd5a639b9cf1397afbc99
5
5
  SHA512:
6
- metadata.gz: f0f291761cfb4aaa3d6151e788dc9200a361deed8556167cc9a219b96f473a9e3373f822c93b2a6940370d0a3d01ad19c17ec1e4e9dfeef48cca399c3273bf7d
7
- data.tar.gz: bd667ecb92422f129e474bd2f37121963f0e618b7166e80f82003462944d2616655034b51f567405c614fbfee2405c32f9dc6b3824e650c5de50f9efdf1cb1d5
6
+ metadata.gz: 1a511cefbd2e347b1dac5bd39b7dc7eb9761b63f132bf794604dc0597dfc093bb8cc61a6f9214956c9b8361acee1ca474a2da39fbbbdea3bdb0aa2b1e5727cb2
7
+ data.tar.gz: 9dd5fb439a6eb1b1c5e8f3590c278085e262cbb6e727e59b014dd961a8453e06828f7e342a5a3d0bc5068cd8fadc4259178b6622f477ebdde237593f5acb015a
@@ -2,6 +2,12 @@
2
2
  # dense
3
3
 
4
4
 
5
+ ## dense 1.1.2 released 2018-07-15
6
+
7
+ * Accept string and symbol keys in path arrays
8
+ * Accept path arrays in Dense::Path.make
9
+
10
+
5
11
  ## dense 1.1.1 released 2018-06-15
6
12
 
7
13
  * Accept `[a;b;c]` union keys
data/Makefile CHANGED
@@ -8,17 +8,20 @@ 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 != '' }"
11
- find spec -name "*.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
11
+ find spec -name "*_spec.rb" | xargs cat | ruby -e "p STDIN.readlines.count { |l| l = l.strip; l[0, 1] != '#' && l != '' }"
12
12
  cl: count_lines
13
13
 
14
14
  gemspec_validate:
15
15
  @echo "---"
16
- ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); s.validate"
16
+ ruby -e "s = eval(File.read(Dir['*.gemspec'].first)); p s.validate"
17
17
  @echo "---"
18
18
 
19
19
  name: gemspec_validate
20
20
  @echo "$(NAME) $(VERSION)"
21
21
 
22
+ cw:
23
+ find lib -name "*.rb" -exec ruby -cw {} \;
24
+
22
25
  build: gemspec_validate
23
26
  gem build $(NAME).gemspec
24
27
  mkdir -p pkg
@@ -27,6 +30,10 @@ build: gemspec_validate
27
30
  push: build
28
31
  gem push pkg/$(NAME)-$(VERSION).gem
29
32
 
33
+ spec:
34
+ bundle exec rspec
35
+ test: spec
36
+
30
37
 
31
- .PHONY: build push
38
+ .PHONY: count_lines gemspec_validate name cw build push spec
32
39
 
@@ -1,7 +1,7 @@
1
1
 
2
2
  module Dense
3
3
 
4
- VERSION = '1.1.1'
4
+ VERSION = '1.1.2'
5
5
  end
6
6
 
7
7
  require 'raabro'
@@ -3,7 +3,7 @@ module Dense; class << self
3
3
 
4
4
  def get(o, path)
5
5
 
6
- pa = Dense::Path.new(path)
6
+ pa = Dense::Path.make(path)
7
7
  r = pa.gather(o).inject([]) { |a, e| a << e[2][e[3]] if e.first; a }
8
8
 
9
9
  pa.narrow(r)
@@ -11,7 +11,7 @@ module Dense; class << self
11
11
 
12
12
  def fetch(o, path, default=::KeyError, &block)
13
13
 
14
- pa = Dense::Path.new(path)
14
+ pa = Dense::Path.make(path)
15
15
  r = pa.gather(o).partition(&:first)
16
16
 
17
17
  if r[0].empty?
@@ -32,7 +32,7 @@ module Dense; class << self
32
32
 
33
33
  def set(o, path, value)
34
34
 
35
- Dense::Path.new(path)
35
+ Dense::Path.make(path)
36
36
  .gather(o)
37
37
  .each { |hit|
38
38
  fail_miss_error(path, hit) if hit[0] == false
@@ -43,7 +43,7 @@ module Dense; class << self
43
43
 
44
44
  def unset(o, path, nofail=false)
45
45
 
46
- pa = Dense::Path.new(path)
46
+ pa = Dense::Path.make(path)
47
47
  hits = pa.gather(o)
48
48
 
49
49
  hits.each { |h| fail miss_error(path, h) unless h[0] } unless nofail
@@ -62,7 +62,7 @@ module Dense; class << self
62
62
 
63
63
  def insert(o, path, value)
64
64
 
65
- Dense::Path.new(path)
65
+ Dense::Path.make(path)
66
66
  .gather(o)
67
67
  .each { |hit|
68
68
  fail_miss_error(path, hit) if hit[0] == false
@@ -77,17 +77,17 @@ module Dense; class << self
77
77
 
78
78
  def has_key?(o, path)
79
79
 
80
- !! Dense::Path.new(path).gather(o).find { |m| m[0] }
80
+ !! Dense::Path.make(path).gather(o).find { |m| m[0] }
81
81
  end
82
82
 
83
83
  def path(path)
84
84
 
85
- Dense::Path.new(path)
85
+ Dense::Path.make(path)
86
86
  end
87
87
 
88
88
  def gather(o, path)
89
89
 
90
- Dense::Path.new(path).gather(o)
90
+ Dense::Path.make(path).gather(o)
91
91
  end
92
92
 
93
93
  protected
@@ -23,16 +23,71 @@ class Dense::Path
23
23
  ) unless @path
24
24
  end
25
25
 
26
- def self.make(path_array)
26
+ class << self
27
27
 
28
- return nil if path_array.nil?
29
- return path_array if path_array.is_a?(Dense::Path)
28
+ def make(path_or_array_or_string)
30
29
 
31
- path = Dense::Path.allocate
32
- path.instance_eval { @path = path_array }
33
- path.instance_eval { @original = path.to_s }
30
+ case (pas = path_or_array_or_string)
31
+ when nil then nil
32
+ when Dense::Path then pas
33
+ when Array then make_from_array(pas)
34
+ when String then Dense::Path.new(pas)
35
+ else
36
+ fail ArgumentError.new(
37
+ "cannot make Dense::Path instance out of #{pas.inspect}")
38
+ end
39
+ end
40
+
41
+ protected
42
+
43
+ def symbolize!(o)
44
+
45
+ if o.is_a?(Array)
46
+ o
47
+ .each { |e| symbolize!(e) }
48
+ elsif o.is_a?(Hash)
49
+ o.keys
50
+ .select { |k| k.is_a?(String) }
51
+ .each { |k| o[k.to_sym] = o.delete(k) }
52
+ end
53
+ end
54
+
55
+ def make_from_array(path_array)
56
+
57
+ symbolize!(path_array)
58
+ validate(path_array)
59
+
60
+ path = Dense::Path.allocate
61
+ path.instance_eval { @path = path_array }
62
+ path.instance_eval { @original = path.to_s }
34
63
 
35
- path
64
+ path
65
+ end
66
+
67
+ def validate(path_array)
68
+
69
+ path_array
70
+ .each_with_index { |elt, i|
71
+ (elt.is_a?(Array) ? elt : [ elt ])
72
+ .each { |e| validate_path_elt(e, i) } }
73
+
74
+ true
75
+ end
76
+
77
+ def validate_path_elt(elt, i)
78
+
79
+ return if elt.is_a?(Integer)
80
+ return if elt.is_a?(String)
81
+ return if [ :dot, :dotstar, :star ].include?(elt)
82
+
83
+ if elt.is_a?(Hash)
84
+ ks = elt.keys.sort
85
+ return if ks == [ :end, :start, :step ]
86
+ return if ks == [ :count, :start ]
87
+ end
88
+
89
+ fail TypeError.new("not a path element (@#{i}): #{elt.inspect}")
90
+ end
36
91
  end
37
92
 
38
93
  def single?
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dense
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-15 00:00:00.000000000 Z
11
+ date: 2018-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro
@@ -80,7 +80,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
80
  version: '0'
81
81
  requirements: []
82
82
  rubyforge_project:
83
- rubygems_version: 2.7.6
83
+ rubygems_version: 2.5.2.3
84
84
  signing_key:
85
85
  specification_version: 4
86
86
  summary: fetching deep in a dense structure