key_tree 0.5.2 → 0.5.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/RELEASE_NOTES.md +13 -0
  3. data/lib/key_tree/forest.rb +28 -19
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee519ff161881da7c9d53d57fe1e762a9e89df557e5f5bb4d3df58e5de1731dd
4
- data.tar.gz: 84b2e06bf6c70acfed4f466a72da5222b9fba028cf551fa7d82a3bbce90351a0
3
+ metadata.gz: 9cfde9ce8a431f8ce658b0d092958dcb97cf237fd1132b459a80191b72ef002b
4
+ data.tar.gz: f51c7e7ce679a1830d929e24114089820f8c1a79082c3e487ef5ac4fa23fa81f
5
5
  SHA512:
6
- metadata.gz: 4d644e3a3d63f34f6edbc0fbc17a2c8f26499d2fe508e186274698b2ff733100f97e5efe62ce2bb4e7c1b35f07282fe5994447e1f7171c57f0cd8408798bbbf8
7
- data.tar.gz: 6dd6f1e13e04bd7a8cbe8cce7d9b36a9ff76ac05c3ffc3fffa5bd12a38fc620f115ff94c37e913b6683aa2980d3c4ddd871b16cebfa622d71a3413fa6a2adf1d
6
+ metadata.gz: a904cca7e3be01bfb902b5c144685fc8c6dd3b52227f22fbd048e8d9e98e1675473bf766cc159ed422b6ac1c35a3b94969beea50dd29bdb528e4242a149a0c77
7
+ data.tar.gz: c9f17cdd2fff51099699d625a72a57bec483859369518c1b273db0478099320426aa24292a71eb07234d8f92ccabcda06875319356c9dae209b267be2657e75e
data/RELEASE_NOTES.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Release Notes
2
2
 
3
+ ## v0.5.3 – 2018-05-25
4
+
5
+ ### Bug fixes
6
+
7
+ #### Fix forest default values
8
+ Previous release broke default value propagation for forests.
9
+
10
+ * c0eccde4 Update forest specs vs default values
11
+ * 35367fd1 Consider Tree default values for Forest#[]
12
+ * 7e10dda5 Add method to find trees with default values
13
+ * 57a320ac Revert "Use proper method to retreive values from trees"
14
+ * 8173775d Make tree_with_key methods private
15
+
3
16
  ## v0.5.2 – 2018-05-19
4
17
 
5
18
  ### Bug fixes
@@ -22,35 +22,20 @@ module KeyTree
22
22
  # key path matches in trees further away, returning nil. This preserves
23
23
  # the constraints that only leaves may contain a value.
24
24
  #
25
- def [](key, &merger)
25
+ def [](key)
26
26
  return super(key) if key.is_a?(Numeric)
27
- fetch(key, &merger)
27
+ tree_with_default_key(key)[key]
28
28
  rescue KeyError
29
29
  nil
30
30
  end
31
31
 
32
32
  def fetch(key)
33
- return tree_with_key(key)[key] unless block_given?
33
+ return tree_with_key(key).fetch(key) unless block_given?
34
34
 
35
- values = trees_with_key(key).map { |tree| tree[key] }
35
+ values = trees_with_key(key).map { |tree| tree.fetch(key) }
36
36
  values.reverse.reduce { |left, right| yield(key, left, right) }
37
37
  end
38
38
 
39
- def tree_with_key(key)
40
- result = trees.detect do |tree|
41
- tree.prefix?(key) || tree.default_key?(key)
42
- end
43
- result || raise(KeyError, "key not found: #{key}")
44
- end
45
-
46
- def trees_with_key(key)
47
- result = trees.select do |tree|
48
- tree.prefix?(key) || tree.default_key?(key)
49
- end
50
- raise(KeyError, "key not found: #{key}") if result.empty?
51
- result
52
- end
53
-
54
39
  def key?(key)
55
40
  trees.any? { |tree| tree.key?(key) }
56
41
  end
@@ -78,5 +63,29 @@ module KeyTree
78
63
  end
79
64
  end
80
65
  end
66
+
67
+ private
68
+
69
+ def tree_with_default_key(key)
70
+ result = trees.detect do |tree|
71
+ tree.prefix?(key) || tree.default_key?(key)
72
+ end
73
+ result || raise(KeyError, %(key not found: "#{key}"))
74
+ end
75
+
76
+ def tree_with_key(key)
77
+ result = trees.detect do |tree|
78
+ tree.prefix?(key)
79
+ end
80
+ result || raise(KeyError, %(key not found: "#{key}"))
81
+ end
82
+
83
+ def trees_with_key(key)
84
+ result = trees.select do |tree|
85
+ tree.prefix?(key)
86
+ end
87
+ raise(KeyError, %(key not found: "#{key}")) if result.empty?
88
+ result
89
+ end
81
90
  end
82
91
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: key_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calle Englund
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-19 00:00:00.000000000 Z
11
+ date: 2018-05-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git-version-bump