recursive-open-struct 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 04d9fd5aa00419789b416be216d67ae225d014422683eb2ab196580ae755eeab
4
- data.tar.gz: 37feccb2944e78db91f9a670e0a92766d857ba012342c93e6bad88f263aaa55b
3
+ metadata.gz: 8969389d2a984d647e29dd46d52d8f82b2ccb1f9c4fd1cab6ba304c8452e06ef
4
+ data.tar.gz: 94dca3f5a423b30e6a22d96b16543cf30d144117222aec40b00b42da2ecb063f
5
5
  SHA512:
6
- metadata.gz: 8993449a07ca130bcaf175ccc81383287c274ed868d4b4d2f597346b9b7d0913ceaa961f33bda36d785728d8767a7caaa5a69701f9369918fa8140168735caad
7
- data.tar.gz: 9ef0c99e43499073de57ac5970a7be3ed99e129a2490ad187fecca29b679e64b13801c13fd8dda763c22321e0b499089321e9e88ecccfb5cfbc5a9913b0e8719
6
+ metadata.gz: 2f15ee9da5eabdbd58dae047b17c8741b2c690ec441f58548bd911147c0a90d1fcc3438cf6749e40105f0190167d84618d11e487c6258bc6c96200311d0c297d
7
+ data.tar.gz: 8b6ee1883f88f12768ef1dd49c70ca9b2321cbb7a158f13aa2fd01c2ca6ff67c3480af380b163090ee248efe553fed5175b76c8dad216ba9dd82a0bf3af387a9
data/AUTHORS.txt CHANGED
@@ -19,6 +19,8 @@ Recursive-open-struct was written by these fine people:
19
19
  * Pedro Sena <sena.pedro@gmail.com>
20
20
  * Peter Yeremenko <peter.yeremenko@gmail.com>
21
21
  * Pirate Praveen <praveen@debian.org>
22
+ * Richard Degenne <richard.degenne+github@gmail.com>
23
+ * Richard Degenne <richard.degenne@gmail.com>
22
24
  * Sebastian Gaul <sebastian@mgvmedia.com>
23
25
  * Thiago Guimaraes <thiagogsr@gmail.com>
24
26
  * Tom Chapin <tchapin@gmail.com>
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 1.2.2 / 2024/06/18
2
+ ==================
3
+
4
+ * [#75](https://github.com/aetherknight/recursive-open-struct/pull/75): Richard
5
+ Degenne: Fix Ruby 3.1 `#freeze`
6
+
1
7
  1.2.1 / 2024/05/27
2
8
  ==================
3
9
 
@@ -6,7 +12,7 @@
6
12
  1.2.0 / 2024/05/27
7
13
  ==================
8
14
 
9
- * [#68](https://github.com/aetherknight/recursive-open-struct/pull/76):
15
+ * [#76](https://github.com/aetherknight/recursive-open-struct/pull/76):
10
16
  IlyaUmanets: Add `raise_on_missing` option, causing ROS to raise
11
17
  `NoMethodError` instead of returning `nil` if a field doesn't exist
12
18
  * MAINT: Switched to Github Actions for CI
@@ -3,5 +3,5 @@
3
3
  require 'ostruct'
4
4
 
5
5
  class RecursiveOpenStruct < OpenStruct
6
- VERSION = "1.2.1"
6
+ VERSION = "1.2.2"
7
7
  end
@@ -137,6 +137,14 @@ class RecursiveOpenStruct < OpenStruct
137
137
  end
138
138
  end
139
139
 
140
+ def freeze
141
+ @table.each_key do |key|
142
+ new_ostruct_member!(key)
143
+ end
144
+
145
+ super
146
+ end
147
+
140
148
  # TODO: Rename to new_ostruct_member! once we care less about Rubies before
141
149
  # 2.4.0.
142
150
  def new_ostruct_member(name)
@@ -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
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.2.1
4
+ version: 1.2.2
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-05-28 00:00:00.000000000 Z
11
+ date: 2024-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler