non_config 0.1.1 → 0.1.2
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/lib/non_config/base.rb +2 -2
- data/lib/non_config/non_hash.rb +24 -9
- data/lib/non_config/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: 40d5f3ba45beed6cd73c6f36907fa400db18567c
|
4
|
+
data.tar.gz: b2d4f6613b83402e2a4d0e973bcd690f3ff43789
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53c7aaeb8b1e9ca54ab5305b51e9a9805d0c5a919c2531a210a46cbc6ebaa5ccf6e2d5982e5c5346fb86b411691914c53416340e5a7efea96a1e01aaa2318315
|
7
|
+
data.tar.gz: cab4eb1062aeb2e04d1ad68b4beb51913a11bfa1d2708ae0a6f5490f7f0d564850608bcbea51573e1021a76641024b2358827379d7ca4dcf29676e30b6ae37a4
|
data/lib/non_config/base.rb
CHANGED
@@ -77,7 +77,7 @@ module NonConfig
|
|
77
77
|
@@files.reverse_each do |_name, file|
|
78
78
|
default = file[key] if default.nil?
|
79
79
|
|
80
|
-
return file[@@env][key] if
|
80
|
+
return file[@@env][key] if file[@@env] && file[@@env][key]
|
81
81
|
return file[key] if !@@env && file[key]
|
82
82
|
end
|
83
83
|
|
@@ -102,7 +102,7 @@ module NonConfig
|
|
102
102
|
if file_alias
|
103
103
|
@@files[file_alias].save
|
104
104
|
else
|
105
|
-
@@files.values.each
|
105
|
+
@@files.values.each(&:save)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
end
|
data/lib/non_config/non_hash.rb
CHANGED
@@ -5,12 +5,16 @@ module NonConfig
|
|
5
5
|
class NonHash < Hash
|
6
6
|
# creates NonHash from Hash with recursive conversion of sub hashes
|
7
7
|
def self.from_hash(hash)
|
8
|
+
new_hash = {}
|
8
9
|
hash.each do |k, v|
|
9
|
-
|
10
|
-
|
10
|
+
new_hash[k] = case v
|
11
|
+
when Hash then from_hash(v)
|
12
|
+
when Array then convert_array_subhashes(v)
|
13
|
+
else v
|
14
|
+
end
|
11
15
|
end
|
12
16
|
|
13
|
-
new.merge(
|
17
|
+
new.merge(new_hash)
|
14
18
|
end
|
15
19
|
|
16
20
|
# recursively converts subhashes of `array` to `self.class`
|
@@ -33,20 +37,31 @@ module NonConfig
|
|
33
37
|
self[m.to_s] || self[m.to_sym]
|
34
38
|
end
|
35
39
|
|
40
|
+
# recursive conversion
|
36
41
|
def to_hash
|
42
|
+
result = {}
|
43
|
+
|
37
44
|
each do |k, v|
|
38
|
-
case v
|
39
|
-
|
40
|
-
|
41
|
-
|
45
|
+
result[k] = case v
|
46
|
+
when self.class then v.to_hash
|
47
|
+
when Array then unconvert_array(v)
|
48
|
+
else v
|
49
|
+
end
|
42
50
|
end
|
51
|
+
|
52
|
+
result
|
53
|
+
end
|
54
|
+
|
55
|
+
#
|
56
|
+
def to_yaml
|
57
|
+
to_hash.to_yaml
|
43
58
|
end
|
44
59
|
|
45
60
|
private
|
46
61
|
|
47
|
-
def
|
62
|
+
def unconvert_array(array)
|
48
63
|
array.map do |e|
|
49
|
-
next
|
64
|
+
next unconvert_array(e) if e.is_a? Array
|
50
65
|
next e.to_hash if e.is_a? self.class
|
51
66
|
e
|
52
67
|
end
|
data/lib/non_config/version.rb
CHANGED