recursive-open-struct 1.3.1 → 2.1.0

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
  SHA256:
3
- metadata.gz: '0020068d7158163ebaa61a88a20513fda9662cabbb36227b9516c4c3579b579d'
4
- data.tar.gz: 95da83b2e949d013183b4f7715ca0820e71e12cebb6a91bd095cbef8c739013c
3
+ metadata.gz: d47dc026bcadbac598558f8734a4bce1cf17312fcbe915925e92b684c41da5b0
4
+ data.tar.gz: 11603a372dbfc88cfa339b0923be134fea27ee333d22e7181fe5f68ef13c6a72
5
5
  SHA512:
6
- metadata.gz: c1a8203c90c1cda06131dd1bd342d928458af25d8a66880c80b9db1ebe5abbf411792b8377f73558e13f1815d8a2e6fb43b7b270cbd21d9202c8dedc9b3cc107
7
- data.tar.gz: c44fdc3e770d7f3be3ad5348174b62d36fe38c245516943195127152a549437fc26bb7a23047d79e3d71a08d12fdeebeb4bf12efd1b759172fedfde03625ecf1
6
+ metadata.gz: 70fd0af15429eb9d81f09c42c36b81f2befc1068d097bc098054d44bb28dbe0545962cfd2f02398e5125d376f58acf9a3691cf0bfbb710317ad677e8081b00f6
7
+ data.tar.gz: 6d2088207848433c2c6e640505df65099f85ead90ae8c598dbe020c6c7b4b185f77f347df6d6e87b693f42807d6d835d73012d42dee1ff843bf430e6cfb0b3a3
@@ -21,8 +21,9 @@ jobs:
21
21
 
22
22
  runs-on: ubuntu-latest
23
23
  strategy:
24
+ fail-fast: false
24
25
  matrix:
25
- ruby-version: ['3.1', '3.2', '3.3', head, jruby, jruby-head]
26
+ ruby-version: ['3.2', '3.3', '3.4', head, jruby, jruby-head]
26
27
 
27
28
  steps:
28
29
  - uses: actions/checkout@v4
@@ -30,7 +31,7 @@ jobs:
30
31
  # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
32
  # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
33
  # uses: ruby/setup-ruby@v1
33
- uses: ruby/setup-ruby@943103cae7d3f1bb1e4951d5fcc7928b40e4b742 # 1.177.1
34
+ uses: ruby/setup-ruby@8aeb6ff8030dd539317f8e1769a044873b56ea71 # 1.268.0
34
35
  with:
35
36
  ruby-version: ${{ matrix.ruby-version }}
36
37
  bundler-cache: true # runs 'bundle install' and caches installed gems automatically
data/AUTHORS.txt CHANGED
@@ -9,6 +9,7 @@ Recursive-open-struct was written by these fine people:
9
9
  * Federico Aloi <federico.aloi@gmail.com>
10
10
  * fervic <roberto@runawaybit.com>
11
11
  * Hartley McGuire <skipkayhil@gmail.com>
12
+ * Hermann Mayer <hermann.mayer92@gmail.com>
12
13
  * Igor Victor <gogainda@yandex.ru>
13
14
  * Ilya Umanets <ilya.umanets@sabiogroup.com>
14
15
  * Jean Boussier <jean.boussier@gmail.com>
@@ -21,11 +22,12 @@ Recursive-open-struct was written by these fine people:
21
22
  * Pedro Sena <sena.pedro@gmail.com>
22
23
  * Peter Yeremenko <peter.yeremenko@gmail.com>
23
24
  * Pirate Praveen <praveen@debian.org>
24
- * Richard Degenne <richard.degenne+github@gmail.com>
25
25
  * Richard Degenne <richard.degenne@gmail.com>
26
+ * Richard Degenne <richard.degenne+github@gmail.com>
26
27
  * Sebastian Gaul <sebastian@mgvmedia.com>
27
28
  * Thiago Guimaraes <thiagogsr@gmail.com>
28
29
  * Tom Chapin <tchapin@gmail.com>
29
30
  * Victor Guzman <victor.guzman@runawaybit.com>
30
31
  * William (B.J.) Snow Orvis <aetherknight@gmail.com>
32
+ * Wynn (B.J.) Snow Orvis <aetherkn@aedifice.org>
31
33
  * Wynn (B.J.) Snow Orvis <aetherknight@gmail.com>
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ 2.1.0 / 2025/12/05
2
+ ==================
3
+
4
+ * [#80](https://github.com/aetherknight/recursive-open-struct/pull/80): Hermann
5
+ Mayer: Added a safety guard for double wrapping.
6
+ * FIX: Avoid loading `ostruct` when processing the gemspec, since it is a
7
+ dependency and it may not be installed/available yet.
8
+
9
+ 2.0.0 / 2024/10/03
10
+ ==================
11
+
12
+ * BREAKING: Restore #72, which is an API-breaking change because it changes
13
+ what data is serialized with marshalling.
14
+
1
15
  1.3.1 / 2024/10/03
2
16
  ==================
3
17
 
@@ -3,5 +3,5 @@
3
3
  require 'ostruct'
4
4
 
5
5
  class RecursiveOpenStruct < OpenStruct
6
- VERSION = "1.3.1"
6
+ VERSION = "2.1.0"
7
7
  end
@@ -29,6 +29,7 @@ class RecursiveOpenStruct < OpenStruct
29
29
  end
30
30
 
31
31
  def initialize(hash=nil, passed_options={})
32
+ hash = hash.to_h if [hash.is_a?(RecursiveOpenStruct), hash.is_a?(OpenStruct)].any?
32
33
  hash ||= {}
33
34
 
34
35
  @options = self.class.default_options.merge!(passed_options).freeze
@@ -40,6 +41,16 @@ class RecursiveOpenStruct < OpenStruct
40
41
  @sub_elements = {}
41
42
  end
42
43
 
44
+ def marshal_load(attributes)
45
+ hash, @options = attributes
46
+ @deep_dup = DeepDup.new(@options)
47
+ @sub_elements = {}
48
+ super(hash)
49
+ end
50
+
51
+ def marshal_dump
52
+ [super, @options]
53
+ end
43
54
 
44
55
  if OpenStruct.public_instance_methods.include?(:initialize_copy)
45
56
  def initialize_copy(orig)
@@ -1,10 +1,12 @@
1
1
  # -*- encoding: utf-8 -*-
2
-
3
- require './lib/recursive_open_struct/version'
2
+ name = "recursive-open-struct"
3
+ version = File.foreach(File.join(__dir__, "lib", "recursive_open_struct", "version.rb")) do |line|
4
+ /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
5
+ end
4
6
 
5
7
  Gem::Specification.new do |s|
6
- s.name = "recursive-open-struct"
7
- s.version = RecursiveOpenStruct::VERSION
8
+ s.name = name
9
+ s.version = version
8
10
  s.authors = ["William (B.J.) Snow Orvis"]
9
11
  s.email = "aetherknight@gmail.com"
10
12
  s.date = Time.now.utc.strftime("%Y-%m-%d")
@@ -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
 
@@ -0,0 +1,70 @@
1
+ require_relative '../spec_helper'
2
+ require 'recursive_open_struct'
3
+
4
+ describe RecursiveOpenStruct do
5
+ describe 'wrapping RecursiveOpenStruct' do
6
+ let(:h) { { :blah => { :another => 'value' } } }
7
+ subject(:ros) { RecursiveOpenStruct.new(RecursiveOpenStruct.new(h)) }
8
+
9
+ it 'can convert the entire hash tree back into a hash' do
10
+ expect(ros.to_h).to eq h
11
+ end
12
+
13
+ it 'can access the flat keys' do
14
+ expect(ros.blah).to be_a(RecursiveOpenStruct)
15
+ end
16
+
17
+ it 'can access the nested keys' do
18
+ expect(ros.blah.another).to eql('value')
19
+ end
20
+
21
+ it 'can be inspected' do
22
+ expect(ros.inspect).to \
23
+ match(/#<RecursiveOpenStruct blah={:?another(: |=>)"value"}>/)
24
+ end
25
+ end
26
+
27
+ describe 'wrapping OpenStruct' do
28
+ let(:h) { { :blah => { :another => 'value' } } }
29
+ subject(:ros) { RecursiveOpenStruct.new(OpenStruct.new(h)) }
30
+
31
+ it 'can convert the entire hash tree back into a hash' do
32
+ expect(ros.to_h).to eq h
33
+ end
34
+
35
+ it 'can access the flat keys' do
36
+ expect(ros.blah).to be_a(RecursiveOpenStruct)
37
+ end
38
+
39
+ it 'can access the nested keys' do
40
+ expect(ros.blah.another).to eql('value')
41
+ end
42
+
43
+ it 'can be inspected' do
44
+ expect(ros.inspect).to \
45
+ match(/#<RecursiveOpenStruct blah={:?another(: |=>)"value"}>/)
46
+ end
47
+ end
48
+
49
+ describe 'wrapping a subclass' do
50
+ let(:h) { { :blah => { :another => 'value' } } }
51
+ let(:subclass) { Class.new(RecursiveOpenStruct) }
52
+ subject(:ros) { subclass.new(subclass.new(h)) }
53
+
54
+ it 'can convert the entire hash tree back into a hash' do
55
+ expect(ros.to_h).to eq h
56
+ end
57
+
58
+ it 'can access the flat keys' do
59
+ expect(ros.blah).to be_a(RecursiveOpenStruct)
60
+ end
61
+
62
+ it 'can access the nested keys' do
63
+ expect(ros.blah.another).to eql('value')
64
+ end
65
+
66
+ it 'can be inspected' do
67
+ expect(ros.inspect).to match(/ blah={:?another(: |=>)"value"}>$/)
68
+ end
69
+ end
70
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recursive-open-struct
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - William (B.J.) Snow Orvis
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-04 00:00:00.000000000 Z
11
+ date: 2025-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,6 +153,7 @@ files:
153
153
  - spec/recursive_open_struct/ostruct_2_3_0_spec.rb
154
154
  - spec/recursive_open_struct/recursion_and_subclassing_spec.rb
155
155
  - spec/recursive_open_struct/recursion_spec.rb
156
+ - spec/recursive_open_struct/wrapping_spec.rb
156
157
  - spec/spec_helper.rb
157
158
  homepage: https://github.com/aetherknight/recursive-open-struct
158
159
  licenses:
@@ -185,4 +186,5 @@ test_files:
185
186
  - spec/recursive_open_struct/ostruct_2_3_0_spec.rb
186
187
  - spec/recursive_open_struct/recursion_and_subclassing_spec.rb
187
188
  - spec/recursive_open_struct/recursion_spec.rb
189
+ - spec/recursive_open_struct/wrapping_spec.rb
188
190
  - spec/spec_helper.rb