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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 37cc8679f6cd7583c945ddc2309df64abee9937a
4
- data.tar.gz: 674ff8cd87c4f2ca24bd6acda16c43d3c0cb8cc9
3
+ metadata.gz: 40d5f3ba45beed6cd73c6f36907fa400db18567c
4
+ data.tar.gz: b2d4f6613b83402e2a4d0e973bcd690f3ff43789
5
5
  SHA512:
6
- metadata.gz: 88c99337ae59f8ff20391ee4bfaf3e33c4a360e8bbf6a1a033733af624f2f3f6f53476c666cbcede43a256332c4f4e03ecbca5925f991be1c0e50338e6dd72f2
7
- data.tar.gz: bd14241bf5f94a83ca3eb7cc59d16a1715b9ce77bb875b9da0f13daee62be0aab586a0d0c1dc4fddf4add14ac5ce631b4c675e0c7d2bcb9ee0018e66846f1ccd
6
+ metadata.gz: 53c7aaeb8b1e9ca54ab5305b51e9a9805d0c5a919c2531a210a46cbc6ebaa5ccf6e2d5982e5c5346fb86b411691914c53416340e5a7efea96a1e01aaa2318315
7
+ data.tar.gz: cab4eb1062aeb2e04d1ad68b4beb51913a11bfa1d2708ae0a6f5490f7f0d564850608bcbea51573e1021a76641024b2358827379d7ca4dcf29676e30b6ae37a4
@@ -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 @@env && file[@@env] && file[@@env][key]
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 &:save
105
+ @@files.values.each(&:save)
106
106
  end
107
107
  end
108
108
  end
@@ -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
- hash[k] = from_hash(v) if v.is_a? Hash
10
- hash[k] = convert_array_subhashes(v) if v.is_a? Array
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(hash)
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.class
39
- when self.class then self[k] = v.to_hash
40
- when Array then self[k] = reconvert_array(v)
41
- end
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 reconvert_array(array)
62
+ def unconvert_array(array)
48
63
  array.map do |e|
49
- next reconvert_array(e) if e.is_a? Array
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
@@ -1,3 +1,3 @@
1
1
  module NonConfig
2
- VERSION = '0.1.1'.freeze
2
+ VERSION = '0.1.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: non_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitriy Non