recursive-open-struct 1.1.3 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +38 -0
- data/.travis.yml +2 -1
- data/AUTHORS.txt +1 -0
- data/CHANGELOG.md +15 -0
- data/README.md +17 -0
- data/lib/recursive_open_struct/version.rb +1 -1
- data/lib/recursive_open_struct.rb +6 -1
- data/spec/recursive_open_struct/indifferent_access_spec.rb +24 -0
- data/spec/recursive_open_struct/ostruct_2_0_0_spec.rb +1 -1
- metadata +7 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d9fd5aa00419789b416be216d67ae225d014422683eb2ab196580ae755eeab
|
4
|
+
data.tar.gz: 37feccb2944e78db91f9a670e0a92766d857ba012342c93e6bad88f263aaa55b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8993449a07ca130bcaf175ccc81383287c274ed868d4b4d2f597346b9b7d0913ceaa961f33bda36d785728d8767a7caaa5a69701f9369918fa8140168735caad
|
7
|
+
data.tar.gz: 9ef0c99e43499073de57ac5970a7be3ed99e129a2490ad187fecca29b679e64b13801c13fd8dda763c22321e0b499089321e9e88ecccfb5cfbc5a9913b0e8719
|
@@ -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
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
|
* Igor Victor <gogainda@yandex.ru>
|
12
|
+
* Ilya Umanets <ilya.umanets@sabiogroup.com>
|
12
13
|
* Jean Boussier <jean.boussier@gmail.com>
|
13
14
|
* Joe Rafaniello <jrafanie@redhat.com>
|
14
15
|
* Kris Dekeyser <kris.dekeyser@libis.be>
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
1.2.1 / 2024/05/27
|
2
|
+
==================
|
3
|
+
|
4
|
+
* Fix a test that is flakey with JRuby
|
5
|
+
|
6
|
+
1.2.0 / 2024/05/27
|
7
|
+
==================
|
8
|
+
|
9
|
+
* [#68](https://github.com/aetherknight/recursive-open-struct/pull/76):
|
10
|
+
IlyaUmanets: Add `raise_on_missing` option, causing ROS to raise
|
11
|
+
`NoMethodError` instead of returning `nil` if a field doesn't exist
|
12
|
+
* MAINT: Switched to Github Actions for CI
|
13
|
+
* MAINT: No longer officially supporting Ruby versions of 3.0.x or earlier,
|
14
|
+
updated CI to test 3.1.x, 3.2.x, 3.3.x
|
15
|
+
|
1
16
|
1.1.3 / 2020/10/15
|
2
17
|
==================
|
3
18
|
|
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
|
|
@@ -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
|
@@ -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
|
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
|
4
|
+
version: 1.2.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:
|
11
|
+
date: 2024-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,7 @@ extra_rdoc_files:
|
|
114
114
|
- README.md
|
115
115
|
files:
|
116
116
|
- ".document"
|
117
|
+
- ".github/workflows/ruby.yml"
|
117
118
|
- ".gitignore"
|
118
119
|
- ".rspec"
|
119
120
|
- ".travis.yml"
|
@@ -143,7 +144,7 @@ homepage: https://github.com/aetherknight/recursive-open-struct
|
|
143
144
|
licenses:
|
144
145
|
- MIT
|
145
146
|
metadata: {}
|
146
|
-
post_install_message:
|
147
|
+
post_install_message:
|
147
148
|
rdoc_options: []
|
148
149
|
require_paths:
|
149
150
|
- lib
|
@@ -158,8 +159,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
159
|
- !ruby/object:Gem::Version
|
159
160
|
version: '0'
|
160
161
|
requirements: []
|
161
|
-
rubygems_version: 3.
|
162
|
-
signing_key:
|
162
|
+
rubygems_version: 3.5.9
|
163
|
+
signing_key:
|
163
164
|
specification_version: 4
|
164
165
|
summary: OpenStruct subclass that returns nested hash attributes as RecursiveOpenStructs
|
165
166
|
test_files:
|