hash_at_path 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash_at_path/core_ext/hash/at_path.rb +4 -4
- data/lib/hash_at_path/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: 2c04db7d7172f566e5ed0d5bea24adf87eaeb654
|
4
|
+
data.tar.gz: c64f2bb7e9c99fa06fb741ccc571e7894a919c78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c904bb4cb986cf123053fca3225be136afe688d2b3373c3e8bcb480c6144c9296cd8ecc90227112b8801656d27dc96d39ffb042ae59aa8df089c18e83a6c2d4
|
7
|
+
data.tar.gz: 6476d9bd98105bf92f1db338e3c2ede76bf4c128ba0419c704d21e1a5f675a7576429d28f9fe87112a7bcf664ec969cbe700978719b8927c711f207ebb8a7169
|
@@ -20,16 +20,16 @@ module HashAtPath
|
|
20
20
|
return nil if val.nil?
|
21
21
|
predicate = path_parts[:predicate] unless predicate == '*'
|
22
22
|
val, predicate = get_value_at_path(predicate, path_parts[:path], val)
|
23
|
-
val = val[predicate.to_i] unless
|
23
|
+
val = val[predicate.to_i] unless is_blank?(predicate) || predicate == '*' || !issa(val, 'Array')
|
24
24
|
end
|
25
25
|
val
|
26
26
|
end
|
27
27
|
|
28
28
|
def get_value_at_path(predicate, path, val)
|
29
|
-
if predicate == '*' && issa(val, 'Array') && !
|
29
|
+
if predicate == '*' && issa(val, 'Array') && !is_blank?(path)
|
30
30
|
val = val.map {|item| unwind_path(item, path)}
|
31
31
|
predicate = nil
|
32
|
-
elsif !
|
32
|
+
elsif !is_blank?(path) && issa(val, 'Hash')
|
33
33
|
val = unwind_path(val, path)
|
34
34
|
end
|
35
35
|
[val, predicate]
|
@@ -49,7 +49,7 @@ module HashAtPath
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# Stolen from activesupport/lib/active_support/core_ext/object/blank.rb
|
52
|
-
def
|
52
|
+
def is_blank?(object)
|
53
53
|
object.respond_to?(:empty?) ? !!object.empty? : !object
|
54
54
|
end
|
55
55
|
end
|
data/lib/hash_at_path/version.rb
CHANGED