recursive-open-struct 1.3.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/recursive_open_struct/version.rb +1 -1
- data/lib/recursive_open_struct.rb +10 -0
- data/spec/recursive_open_struct/recursion_spec.rb +19 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98947e3672ac602b5065c7cbd9db4712ad76f37f1bd93e7fe5b26bd03d45b868
|
4
|
+
data.tar.gz: 91d09d9bc788f331837fb9edfd5e1d006088becd07770ecea52a5b1dee2f659a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e37aaa9409d7cb1bf0b8999603bbaeb7345a2496784127ef2612b49b765a9a745b29fb4d6dcb3f5aee8045a89a2b05370611486db48be3e630cf8f22cfccfca6
|
7
|
+
data.tar.gz: 4d8cc8cd0140f749f7a924c06469a4d1cd1709fa3464cc72cec250c296e29cd1936fbc1dd6e9852c4fb904f6e0c1e65847b9ba311f48d41d75de12097ac2a409
|
data/CHANGELOG.md
CHANGED
@@ -40,6 +40,16 @@ class RecursiveOpenStruct < OpenStruct
|
|
40
40
|
@sub_elements = {}
|
41
41
|
end
|
42
42
|
|
43
|
+
def marshal_load(attributes)
|
44
|
+
hash, @options = attributes
|
45
|
+
@deep_dup = DeepDup.new(@options)
|
46
|
+
@sub_elements = {}
|
47
|
+
super(hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
def marshal_dump
|
51
|
+
[super, @options]
|
52
|
+
end
|
43
53
|
|
44
54
|
if OpenStruct.public_instance_methods.include?(:initialize_copy)
|
45
55
|
def initialize_copy(orig)
|
@@ -37,6 +37,14 @@ describe RecursiveOpenStruct do
|
|
37
37
|
expect(ros.blah.changed).to eql 'backing'
|
38
38
|
end
|
39
39
|
|
40
|
+
it "handles being dump then loaded by Marshal" do
|
41
|
+
foo_struct = [RecursiveOpenStruct.new]
|
42
|
+
bar_struct = RecursiveOpenStruct.new(foo: foo_struct)
|
43
|
+
serialized = Marshal.dump(bar_struct)
|
44
|
+
|
45
|
+
expect(Marshal.load(serialized).foo).to eq(foo_struct)
|
46
|
+
end
|
47
|
+
|
40
48
|
describe "handling loops in the original Hashes" do
|
41
49
|
let(:h1) { { :a => 'a'} }
|
42
50
|
let(:h2) { { :a => 'b', :h1 => h1 } }
|
@@ -182,6 +190,17 @@ describe RecursiveOpenStruct do
|
|
182
190
|
let(:blah_list) { [ { :foo => '1' }, { :foo => '2' }, 'baz' ] }
|
183
191
|
let(:h) { { :blah => blah_list } }
|
184
192
|
|
193
|
+
context "when dump and loaded by Marshal" do
|
194
|
+
let(:test) { RecursiveOpenStruct.new(h, :recurse_over_arrays => true) }
|
195
|
+
subject { Marshal.load(Marshal.dump(test))}
|
196
|
+
|
197
|
+
it { expect(subject.blah.length).to eq 3 }
|
198
|
+
it { expect(subject.blah[0].foo).to eq '1' }
|
199
|
+
it { expect(subject.blah[1].foo).to eq '2' }
|
200
|
+
it { expect(subject.blah_as_a_hash).to eq blah_list }
|
201
|
+
it { expect(subject.blah[2]).to eq 'baz' }
|
202
|
+
end
|
203
|
+
|
185
204
|
context "when recursing over arrays is enabled" do
|
186
205
|
subject { RecursiveOpenStruct.new(h, :recurse_over_arrays => true) }
|
187
206
|
|