collapsium 0.6.0 → 0.6.1
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +2 -0
- data/lib/collapsium/pathed_access.rb +1 -1
- data/lib/collapsium/recursive_fetch.rb +24 -10
- data/lib/collapsium/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 63b5ae2bec3820d536814099c538f53f32ce3d14
|
4
|
+
data.tar.gz: d18f3d4bd528f98cf7b92a31a94da97211efb5d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1bc5ee36f8b47a7a7e1acffa6d80ef1d4dc400e4459418542e7dfaf99fed4d9fb76493ade6e37f5b50faecaad99a6c641ec7f6f78ece791f225269750ba4e16a
|
7
|
+
data.tar.gz: 7c5dc2d3f39681cfb909bc4259ca577707c90884e8bd3a80819ad5b84e79689d57fb1850856b25cf7bc18245a350f24b1037d324ce13e3ea63a090fbef848088
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -41,6 +41,8 @@ that is ActiveSupport...
|
|
41
41
|
recursively.
|
42
42
|
- The `RecursiveSort` module provides a `#recursive_sort` function which sorts
|
43
43
|
recursively.
|
44
|
+
- The `RecursiveFetch` module provides `#recursve_fetch` and `#recursive_fetch_one`
|
45
|
+
which searches recursively for all/the first ocurrence(s) of a key respectively.
|
44
46
|
- The `PathedAccess` module provides a pathed access method to nested Hashes:
|
45
47
|
|
46
48
|
```ruby
|
@@ -91,7 +91,7 @@ module Collapsium
|
|
91
91
|
|
92
92
|
# Array methods we're modifying here are indexed, so the first argument
|
93
93
|
# must be an integer. Let's make it so :)
|
94
|
-
if leaf.is_a? Array
|
94
|
+
if leaf.is_a? Array and the_args[0][0] =~ /[0-9]/
|
95
95
|
the_args[0] = the_args[0].to_i
|
96
96
|
end
|
97
97
|
|
@@ -27,13 +27,20 @@ module Collapsium
|
|
27
27
|
# the match value passed to the block.
|
28
28
|
def recursive_fetch_one(key, default = nil, &block)
|
29
29
|
# Start simple at the top level.
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
# rubocop:disable Lint/HandleExceptions
|
31
|
+
begin
|
32
|
+
result = fetch(key, default)
|
33
|
+
if result != default
|
34
|
+
if not block.nil?
|
35
|
+
result = yield self, result, default
|
36
|
+
end
|
37
|
+
return result
|
34
38
|
end
|
35
|
-
|
39
|
+
rescue TypeError
|
40
|
+
# Happens if self is an Array and key is a String that cannot
|
41
|
+
# be converted to Integer.
|
36
42
|
end
|
43
|
+
# rubocop:enable Lint/HandleExceptions
|
37
44
|
|
38
45
|
# We have to recurse for nested values
|
39
46
|
result = map do |_, v|
|
@@ -60,13 +67,20 @@ module Collapsium
|
|
60
67
|
result = []
|
61
68
|
|
62
69
|
# Start simple at the top level.
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
70
|
+
# rubocop:disable Lint/HandleExceptions
|
71
|
+
begin
|
72
|
+
ret = fetch(key, default)
|
73
|
+
if ret != default
|
74
|
+
if not block.nil?
|
75
|
+
ret = yield self, ret, default
|
76
|
+
end
|
77
|
+
result << ret
|
67
78
|
end
|
68
|
-
|
79
|
+
rescue TypeError
|
80
|
+
# Happens if self is an Array and key is a String that cannot
|
81
|
+
# be converted to Integer.
|
69
82
|
end
|
83
|
+
# rubocop:enable Lint/HandleExceptions
|
70
84
|
|
71
85
|
# We have to recurse for nested values
|
72
86
|
result += map do |_, v|
|
data/lib/collapsium/version.rb
CHANGED