settingable 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/settingable/hash.rb +16 -2
- data/lib/settingable/version.rb +1 -1
- data/spec/settingable/hash_spec.rb +10 -0
- 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: 3314a1c9c8645eb3fedf8a478134e4c373b19030
|
4
|
+
data.tar.gz: 142e2b082c6d331cccb0cc9908a94cf636a21cfc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a52f69616659d7bb3839678135e057d489b9131894d7df88bc40c4933dad4cebb172d2d8b1eeef8ff2b39a26114fe5e001cb888a4621ca63460159464eb4874d
|
7
|
+
data.tar.gz: 6b3ede167ad83aa224cc1bf2a33151fa4147cc3d7b5c8ee8f658ef28476ffd5896ad77922679cba05d0b29db2afbc4e5619ed115e8162251af80d587b7997939
|
data/lib/settingable/hash.rb
CHANGED
@@ -89,6 +89,20 @@ module Settingable
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
# Converts this hash into a normal hash. Since we recursively
|
93
|
+
# converted every hash value into a {Settingable::Hash}, we have
|
94
|
+
# to undo that for the new hash.
|
95
|
+
#
|
96
|
+
# @return [::Hash]
|
97
|
+
def to_h
|
98
|
+
out = {}
|
99
|
+
each do |key, value|
|
100
|
+
out[key] = convert(value, true)
|
101
|
+
end
|
102
|
+
|
103
|
+
out
|
104
|
+
end
|
105
|
+
|
92
106
|
private
|
93
107
|
|
94
108
|
# Converts the value to a {Settingable::Hash}, if it is a regular
|
@@ -96,9 +110,9 @@ module Settingable
|
|
96
110
|
#
|
97
111
|
# @param value [Hash, Object]
|
98
112
|
# @return [Settingable::Hash, Object]
|
99
|
-
def convert(value)
|
113
|
+
def convert(value, invert = false)
|
100
114
|
if value.is_a?(::Hash)
|
101
|
-
Settingable::Hash.new(value)
|
115
|
+
invert ? value.to_h : Settingable::Hash.new(value)
|
102
116
|
else
|
103
117
|
value
|
104
118
|
end
|
data/lib/settingable/version.rb
CHANGED
@@ -21,6 +21,16 @@ RSpec.describe Settingable::Hash do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
describe "#to_h" do
|
25
|
+
it "gives a regular hash" do
|
26
|
+
expect(subject.to_h).to be_a ::Hash
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has regular hash values" do
|
30
|
+
expect(subject.to_h[:foo]).to be_a ::Hash
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
24
34
|
describe "#[]=" do
|
25
35
|
it "converts hash values" do
|
26
36
|
subject[:hello] = { foo: { bar: "baz" } }
|