vine 0.3 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/vine.rb +28 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1fa94ad02bba2c38a0b59973a228a1b1e2e93e73
|
4
|
+
data.tar.gz: 7b46cab730077054f6c60a971b4e83a29ad8f278
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a035fd5298a4f365470747797d02ad26752c9989de4965489de0c39a538efe4b74fa32028964f91c49b97fdf0e0f777e3535f8a55553ee7dbc427d7b8f59c2dd
|
7
|
+
data.tar.gz: ed2493896073cb7d91b377a9f83b01bc79b4d706d4af69c01ffadb06c3040d05d19068ed95ac64d487f3c64ebb349491ed0f9e8ecc9a1264465030f981a97bc3
|
data/lib/vine.rb
CHANGED
@@ -26,6 +26,34 @@ class Hash
|
|
26
26
|
value
|
27
27
|
end
|
28
28
|
|
29
|
+
def set(path, value)
|
30
|
+
keys = []
|
31
|
+
path = path.to_s.split('.')
|
32
|
+
|
33
|
+
[*path, nil].each_cons(2) do |key,nextkey|
|
34
|
+
tmp_hash = keys.inject(self, :fetch)
|
35
|
+
|
36
|
+
if key.to_i.to_s == key
|
37
|
+
key = key.to_i
|
38
|
+
elsif tmp_hash[key].nil?
|
39
|
+
key = key.to_sym
|
40
|
+
end
|
41
|
+
|
42
|
+
if tmp_hash[key].nil?
|
43
|
+
tmp_hash[key] = {}
|
44
|
+
elsif nextkey.to_i.to_s == nextkey && !tmp_hash[key].is_a?(Array)
|
45
|
+
tmp_hash[key] = []
|
46
|
+
elsif !nextkey.nil? && !tmp_hash[key].is_a?(Hash)
|
47
|
+
tmp_hash[key] = {}
|
48
|
+
end
|
49
|
+
|
50
|
+
keys << key
|
51
|
+
end # each_cons
|
52
|
+
|
53
|
+
last_key = keys.pop
|
54
|
+
keys.inject(self, :fetch)[last_key] = value
|
55
|
+
end
|
56
|
+
|
29
57
|
alias :vine :access
|
30
58
|
|
31
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cheng Guangnan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Access nested Hash (JSON) with a string path
|
14
14
|
email: chengguangnan@icloud.com
|