recursive-open-struct 1.1.3 → 1.3.1

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: 3cc972f20fd1aba4f8eea6fe1766c17c7d9e663a3ed999e8375549ac37ae4b08
4
- data.tar.gz: 9c0d0230d431aedeae47f0f2026d77196dfb230c3ebe9359763b4265c9a4c4d6
3
+ metadata.gz: '0020068d7158163ebaa61a88a20513fda9662cabbb36227b9516c4c3579b579d'
4
+ data.tar.gz: 95da83b2e949d013183b4f7715ca0820e71e12cebb6a91bd095cbef8c739013c
5
5
  SHA512:
6
- metadata.gz: dcdc725048e24182c562551875b2fa90d100248008af5dd4a974bb8df82f48ec5f618b3d76458d16f868b76b55263e96d3576a6d92f5ace69979beb29ae3213f
7
- data.tar.gz: d67c50798fcaa7ca49003a924e57df0a22e83a5d688ef6ff90b61f462855f2b6ef8882e5873c0994558416030a9b265fe60cccfe586fd5bf9688e463d92279fe
6
+ metadata.gz: c1a8203c90c1cda06131dd1bd342d928458af25d8a66880c80b9db1ebe5abbf411792b8377f73558e13f1815d8a2e6fb43b7b270cbd21d9202c8dedc9b3cc107
7
+ data.tar.gz: c44fdc3e770d7f3be3ad5348174b62d36fe38c245516943195127152a549437fc26bb7a23047d79e3d71a08d12fdeebeb4bf12efd1b759172fedfde03625ecf1
@@ -0,0 +1,38 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Ruby
9
+
10
+ on:
11
+ push:
12
+ branches: [ "main" ]
13
+ pull_request:
14
+ branches: [ "main" ]
15
+
16
+ permissions:
17
+ contents: read
18
+
19
+ jobs:
20
+ test:
21
+
22
+ runs-on: ubuntu-latest
23
+ strategy:
24
+ matrix:
25
+ ruby-version: ['3.1', '3.2', '3.3', head, jruby, jruby-head]
26
+
27
+ steps:
28
+ - uses: actions/checkout@v4
29
+ - name: Set up Ruby
30
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
+ # uses: ruby/setup-ruby@v1
33
+ uses: ruby/setup-ruby@943103cae7d3f1bb1e4951d5fcc7928b40e4b742 # 1.177.1
34
+ with:
35
+ ruby-version: ${{ matrix.ruby-version }}
36
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
37
+ - name: Run tests
38
+ run: bundle exec rake
data/.travis.yml CHANGED
@@ -11,7 +11,8 @@ rvm:
11
11
  # Current stable supported by Travis
12
12
  - 2.5.8
13
13
  - 2.6.6
14
- - 2.7.1
14
+ - 2.7.2
15
+ - 3.0.0
15
16
  - jruby-9.1.9.0
16
17
  # Future
17
18
  - ruby-head
data/AUTHORS.txt CHANGED
@@ -8,18 +8,24 @@ Recursive-open-struct was written by these fine people:
8
8
  * Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl>
9
9
  * Federico Aloi <federico.aloi@gmail.com>
10
10
  * fervic <roberto@runawaybit.com>
11
+ * Hartley McGuire <skipkayhil@gmail.com>
11
12
  * Igor Victor <gogainda@yandex.ru>
13
+ * Ilya Umanets <ilya.umanets@sabiogroup.com>
12
14
  * Jean Boussier <jean.boussier@gmail.com>
13
15
  * Joe Rafaniello <jrafanie@redhat.com>
14
16
  * Kris Dekeyser <kris.dekeyser@libis.be>
17
+ * Maple Ong <maple.ong@gusto.com>
15
18
  * Matt Culpepper <matt@culpepper.co>
16
19
  * Matthew O'Riordan <matthew.oriordan@gmail.com>
17
20
  * Offirmo <offirmo.net@gmail.com>
18
21
  * Pedro Sena <sena.pedro@gmail.com>
19
22
  * Peter Yeremenko <peter.yeremenko@gmail.com>
20
23
  * Pirate Praveen <praveen@debian.org>
24
+ * Richard Degenne <richard.degenne+github@gmail.com>
25
+ * Richard Degenne <richard.degenne@gmail.com>
21
26
  * Sebastian Gaul <sebastian@mgvmedia.com>
22
27
  * Thiago Guimaraes <thiagogsr@gmail.com>
23
28
  * Tom Chapin <tchapin@gmail.com>
24
29
  * Victor Guzman <victor.guzman@runawaybit.com>
25
30
  * William (B.J.) Snow Orvis <aetherknight@gmail.com>
31
+ * Wynn (B.J.) Snow Orvis <aetherknight@gmail.com>
data/CHANGELOG.md CHANGED
@@ -1,3 +1,41 @@
1
+ 1.3.1 / 2024/10/03
2
+ ==================
3
+
4
+ * FIX for
5
+ [#79](https://github.com/aetherknight/recursive-open-struct/issues/79):
6
+ Revert #72's change to marshalling and dumping since it is an API-breaking
7
+ change. It will be re-added in a new major version after releasing a fix.
8
+
9
+ 1.3.0 / 2024/10/01
10
+ ==================
11
+
12
+ * [#72](https://github.com/aetherknight/recursive-open-struct/pull/72): Maple
13
+ Ong: Better handle marshalling and dumping ROS
14
+ * [#78](https://github.com/aetherknight/recursive-open-struct/pull/78): Hartley
15
+ McGuire: Add ostruct as a dependency since newer Ruby versions are going to
16
+ remove it
17
+
18
+ 1.2.2 / 2024/06/18
19
+ ==================
20
+
21
+ * [#75](https://github.com/aetherknight/recursive-open-struct/pull/75): Richard
22
+ Degenne: Fix Ruby 3.1 `#freeze`
23
+
24
+ 1.2.1 / 2024/05/27
25
+ ==================
26
+
27
+ * Fix a test that is flakey with JRuby
28
+
29
+ 1.2.0 / 2024/05/27
30
+ ==================
31
+
32
+ * [#76](https://github.com/aetherknight/recursive-open-struct/pull/76):
33
+ IlyaUmanets: Add `raise_on_missing` option, causing ROS to raise
34
+ `NoMethodError` instead of returning `nil` if a field doesn't exist
35
+ * MAINT: Switched to Github Actions for CI
36
+ * MAINT: No longer officially supporting Ruby versions of 3.0.x or earlier,
37
+ updated CI to test 3.1.x, 3.2.x, 3.3.x
38
+
1
39
  1.1.3 / 2020/10/15
2
40
  ==================
3
41
 
data/README.md CHANGED
@@ -62,6 +62,23 @@ ros = RecursiveOpenStruct.new(h, preserve_original_keys: true)
62
62
  ros.to_h # => { 'fear' => 'is', 'the' => 'mindkiller' }
63
63
  ```
64
64
 
65
+ ### Optional: Raise error on missing attribute
66
+
67
+ This option allows to raise an error if you try to call an attribute you didn't specify in hash
68
+
69
+ ```ruby
70
+ h = { 'fear' => 'is', 'the' => 'mindkiller' } }
71
+ ros = RecursiveOpenStruct.new(h, raise_on_missing: true)
72
+ ros.undefined # => undefined method `undefined' for #<RecursiveOpenStruct fear="is", the="mindkiller">
73
+ ```
74
+
75
+ The default behaviour returns nil
76
+
77
+ ```ruby
78
+ h = { 'fear' => 'is', 'the' => 'mindkiller' } }
79
+ ros = RecursiveOpenStruct.new(h)
80
+ ros.undefined # => nil
81
+ ```
65
82
 
66
83
  ## Installation
67
84
 
@@ -3,5 +3,5 @@
3
3
  require 'ostruct'
4
4
 
5
5
  class RecursiveOpenStruct < OpenStruct
6
- VERSION = "1.1.3"
6
+ VERSION = "1.3.1"
7
7
  end
@@ -23,7 +23,8 @@ class RecursiveOpenStruct < OpenStruct
23
23
  {
24
24
  mutate_input_hash: false,
25
25
  recurse_over_arrays: false,
26
- preserve_original_keys: false
26
+ preserve_original_keys: false,
27
+ raise_on_missing: false
27
28
  }
28
29
  end
29
30
 
@@ -124,6 +125,10 @@ class RecursiveOpenStruct < OpenStruct
124
125
  if @table.key?(_get_key_from_table_(key))
125
126
  new_ostruct_member!(key)
126
127
  public_send(mid)
128
+ elsif @options[:raise_on_missing]
129
+ err = NoMethodError.new "undefined method `#{mid}' for #{self}", mid, args
130
+ err.set_backtrace caller(1)
131
+ raise err
127
132
  end
128
133
  else
129
134
  err = NoMethodError.new "undefined method `#{mid}' for #{self}", mid, args
@@ -132,6 +137,14 @@ class RecursiveOpenStruct < OpenStruct
132
137
  end
133
138
  end
134
139
 
140
+ def freeze
141
+ @table.each_key do |key|
142
+ new_ostruct_member!(key)
143
+ end
144
+
145
+ super
146
+ end
147
+
135
148
  # TODO: Rename to new_ostruct_member! once we care less about Rubies before
136
149
  # 2.4.0.
137
150
  def new_ostruct_member(name)
@@ -40,5 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.add_development_dependency('rdoc', [">= 0"])
41
41
  s.add_development_dependency('rspec', "~> 3.2")
42
42
  s.add_development_dependency('simplecov', [">= 0"])
43
+
44
+ s.add_dependency('ostruct')
43
45
  end
44
46
 
@@ -160,6 +160,30 @@ describe RecursiveOpenStruct do
160
160
  end
161
161
  end
162
162
 
163
+ context 'when undefined method' do
164
+ context 'when raise_on_missing is enabled' do
165
+ subject(:recursive) { RecursiveOpenStruct.new(recursive_hash, raise_on_missing: true) }
166
+ let(:recursive_hash) { {:foo => [ {'bar' => [ { 'foo' => :bar} ] } ] } }
167
+
168
+ specify 'raises NoMethodError' do
169
+ expect {
170
+ recursive.undefined_method
171
+ }.to raise_error(NoMethodError)
172
+ end
173
+ end
174
+
175
+ context 'when raise_on_missing is disabled' do
176
+ context 'preserves the original keys' do
177
+ subject(:recursive) { RecursiveOpenStruct.new(recursive_hash) }
178
+ let(:recursive_hash) { {:foo => [ {'bar' => [ { 'foo' => :bar} ] } ] } }
179
+
180
+ specify 'returns nil' do
181
+ expect(recursive.undefined_method).to be_nil
182
+ end
183
+ end
184
+ end
185
+ end
186
+
163
187
  end
164
188
 
165
189
  end
@@ -108,5 +108,41 @@ describe RecursiveOpenStruct do
108
108
  it { expect(subject.methods.map(&:to_sym)).to_not include :asdf= }
109
109
  end # describe #methods
110
110
  end # describe handling of arbitrary attributes
111
+
112
+ describe "handling of freezing" do
113
+ let(:hash) { { :asdf => 'John Smith' } }
114
+
115
+ before do
116
+ ros.freeze
117
+ end
118
+
119
+ it "can read existing keys" do
120
+ expect(ros.asdf).to eq 'John Smith'
121
+ end
122
+
123
+ it "cannot write new keys" do
124
+ expect { ros.new_key = 'new_value' }.to raise_error FrozenError
125
+ end
126
+
127
+ it "cannot write existing keys" do
128
+ expect { ros.asdf = 'new_value' }.to raise_error FrozenError
129
+ end
130
+
131
+ context "with recursive structure" do
132
+ let(:hash) { { :key => { :subkey => 42 } } }
133
+
134
+ it "can read existing sub-elements" do
135
+ expect(ros.key.subkey).to eq 42
136
+ end
137
+
138
+ it "can write new sub-elements" do
139
+ expect { ros.key.new_subkey = 43 }.not_to raise_error
140
+ end
141
+
142
+ it "can write existing sub-elements" do
143
+ expect { ros.key.subkey = 43 }.not_to raise_error
144
+ end
145
+ end
146
+ end
111
147
  end # describe behavior it inherits from OpenStruct
112
148
  end
@@ -89,7 +89,7 @@ describe RecursiveOpenStruct do
89
89
 
90
90
  context "hash" do
91
91
  it "calculates table hash" do
92
- expect(ros.hash).to be ros.instance_variable_get('@table').hash
92
+ expect(ros.hash).to eq(ros.instance_variable_get('@table').hash)
93
93
  end
94
94
 
95
95
  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.1.3
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William (B.J.) Snow Orvis
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-16 00:00:00.000000000 Z
11
+ date: 2024-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: ostruct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: |
98
112
  RecursiveOpenStruct is a subclass of OpenStruct. It differs from
99
113
  OpenStruct in that it allows nested hashes to be treated in a recursive
@@ -114,6 +128,7 @@ extra_rdoc_files:
114
128
  - README.md
115
129
  files:
116
130
  - ".document"
131
+ - ".github/workflows/ruby.yml"
117
132
  - ".gitignore"
118
133
  - ".rspec"
119
134
  - ".travis.yml"
@@ -143,7 +158,7 @@ homepage: https://github.com/aetherknight/recursive-open-struct
143
158
  licenses:
144
159
  - MIT
145
160
  metadata: {}
146
- post_install_message:
161
+ post_install_message:
147
162
  rdoc_options: []
148
163
  require_paths:
149
164
  - lib
@@ -158,8 +173,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
173
  - !ruby/object:Gem::Version
159
174
  version: '0'
160
175
  requirements: []
161
- rubygems_version: 3.1.2
162
- signing_key:
176
+ rubygems_version: 3.5.9
177
+ signing_key:
163
178
  specification_version: 4
164
179
  summary: OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
165
180
  test_files: