super_struct 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/super_struct.rb +9 -0
- data/lib/super_struct/version.rb +1 -1
- data/spec/super_struct_spec.rb +16 -6
- 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: 858dfb69885a2c237749fccd4b4baea129406d45
|
4
|
+
data.tar.gz: 18b2e17b26d666a68be9474cf6d3d271f264034d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: feaf73a92d3873d7ceedd720ae5fb1ae5dfc7d4a1e4ca23a2478c51e056c00d0835e31b6465bb7d26cda91027fe69ee6fffdd42821aeef4ca102208f52de6821
|
7
|
+
data.tar.gz: cfdf802e48de761ecba5854359c5cebb9b84e7aad052697d0bc58ce933a1484b2af875773a0dfcd2f70555545c211b1a78e6906a9a5266b7b254162095fde262
|
data/lib/super_struct.rb
CHANGED
@@ -20,6 +20,15 @@ module SuperStruct
|
|
20
20
|
attributes
|
21
21
|
end
|
22
22
|
end
|
23
|
+
|
24
|
+
def deep_convert!
|
25
|
+
members.each do |member|
|
26
|
+
if self[member].respond_to?(:has_key?)
|
27
|
+
self[member] = ::SuperStruct.from_hash(self[member])
|
28
|
+
self[member].deep_convert!
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
23
32
|
end
|
24
33
|
|
25
34
|
def self.new(array_or_hash, &block)
|
data/lib/super_struct/version.rb
CHANGED
data/spec/super_struct_spec.rb
CHANGED
@@ -48,15 +48,25 @@ describe SuperStruct do
|
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
|
-
describe '#members' do
|
52
|
-
it 'is the keys given to the constructor, sorted' do
|
53
|
-
expect(subject.members).to eq input.keys.sort
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
51
|
describe '#attributes' do
|
58
52
|
it 'is a hash of the attributes and their values' do
|
59
53
|
expect(subject.attributes).to eq constructor_input
|
60
54
|
end
|
61
55
|
end
|
56
|
+
|
57
|
+
describe '#deep_convert!' do
|
58
|
+
let(:input) { { foo: { fiz: :bang } } }
|
59
|
+
subject { SuperStruct.from_hash(input) }
|
60
|
+
|
61
|
+
it 'converts all hashes within itself to SuperStructs' do
|
62
|
+
expect {
|
63
|
+
subject.deep_convert!
|
64
|
+
}.to change {
|
65
|
+
subject.foo
|
66
|
+
}.from(Hash).to(Struct)
|
67
|
+
#expect(subject.foo).to be_a Hash
|
68
|
+
#subject.deep_convert!
|
69
|
+
#expect(subject.foo).to be_a Struct
|
70
|
+
end
|
71
|
+
end
|
62
72
|
end
|