inprovise 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/inprovise/config.rb +26 -11
- data/lib/inprovise/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MmQ4NGYyYzAzM2U3NGJlY2EzMDFlMjU1OGJiYzdlMmQ2YjJkMzZmZA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjFhYmFkMDI1NTFiZjExOTJiMzBhODhlYjdmYjBlYzQwZmNjZTFlMg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWQ2NTFhYzk5OGYzODkyZDA0ODA4ZmMxMTc0MTVlMjFmN2VkYTUxYTIzNGI5
|
10
|
+
ZmVkNjFhZDY2MjFhNzZjNzQxMWE5MTY4YTE2ZjI4NzZhOWNjNjdiNDE5MDUx
|
11
|
+
YjFjNzk2OTQ3YzA3Mzg2YTYyYTY0YTM2Yzg5Nzc5YmRmYTdjMDM=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
OWUwN2ZkNDk4NTYzNDljNThkMDgwNjEzZDVmMTY4Y2RmZTg2YTA2ODdhODAy
|
14
|
+
NWRmY2E1OWJjMjg4MzZjMTQxMzkzYmMwOGVmNDUxOTc4ZTUxYzQ3MmU0NjBk
|
15
|
+
ZmEzMjhlM2Y4ODljMjIyZjFhNDVkZjEzZWY3ZmVjNjYxNmVkZDE=
|
data/lib/inprovise/config.rb
CHANGED
@@ -7,29 +7,41 @@ class Inprovise::Config
|
|
7
7
|
|
8
8
|
def initialize(other=nil)
|
9
9
|
@table = {}
|
10
|
-
copy!(other
|
10
|
+
copy!(other) if other
|
11
11
|
end
|
12
12
|
|
13
|
-
def _k_(key)
|
14
|
-
Symbol === key ? key : key.to_s.to_sym
|
15
|
-
end
|
16
|
-
private :_k_
|
17
|
-
|
18
13
|
def _v_(val)
|
19
14
|
Hash === val ? self.class.new.merge!(val) : val
|
20
15
|
end
|
21
16
|
private :_v_
|
22
17
|
|
18
|
+
def get(key)
|
19
|
+
Symbol === key ? @table[key] : key.to_s.split('.').reduce(@table) { |t,k| t[k.to_sym] ||= self.class.new }
|
20
|
+
end
|
21
|
+
|
22
|
+
def set(key, val)
|
23
|
+
if Symbol === key
|
24
|
+
@table[key] = _v_(val)
|
25
|
+
else
|
26
|
+
vk = (path = key.to_s.split('.')).pop
|
27
|
+
path.reduce(@table) { |t,k| t[k.to_sym] ||= self.class.new }[vk.to_sym] = _v_(val)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
23
31
|
def [](key)
|
24
|
-
|
32
|
+
get(key)
|
25
33
|
end
|
26
34
|
|
27
35
|
def []=(key, val)
|
28
|
-
|
36
|
+
set(key, val)
|
29
37
|
end
|
30
38
|
|
31
39
|
def has_key?(key)
|
32
|
-
|
40
|
+
if Symbol === key
|
41
|
+
@table.has_key?(key)
|
42
|
+
else
|
43
|
+
!(key.to_s.split('.').reduce(@table) { |t,k| t && t.has_key?(k.to_sym) && self.class === t[k.to_sym] ? t[k.to_sym] : nil }).nil?
|
44
|
+
end
|
33
45
|
end
|
34
46
|
|
35
47
|
def empty?
|
@@ -80,12 +92,15 @@ class Inprovise::Config
|
|
80
92
|
end
|
81
93
|
|
82
94
|
def to_h
|
83
|
-
@table
|
95
|
+
@table.reduce({}) do |hsh, (k,v)|
|
96
|
+
hsh[k] = self.class === v ? v.to_h : v
|
97
|
+
hsh
|
98
|
+
end
|
84
99
|
end
|
85
100
|
|
86
101
|
def method_missing(method, *args)
|
87
102
|
if /(.*)=$/ =~ method.to_s
|
88
|
-
self[$1] = (args.size > 1 ? args : args.shift)
|
103
|
+
self[$1.to_sym] = (args.size > 1 ? args : args.shift)
|
89
104
|
else
|
90
105
|
self[method]
|
91
106
|
end
|
data/lib/inprovise/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inprovise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Corino
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-09-
|
11
|
+
date: 2016-09-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored
|