private_attr 1.0.0 → 2.0.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 +5 -5
- data/.travis.yml +6 -2
- data/README.md +8 -2
- data/lib/private_attr/everywhere.rb +6 -0
- data/lib/private_attr/version.rb +3 -1
- data/lib/private_attr.rb +18 -6
- data/private_attr.gemspec +2 -1
- data/spec/private_attr/everywhere_spec.rb +20 -0
- data/spec/private_attr_spec.rb +219 -105
- metadata +25 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 88d9a3ef59b6c3f35666213427fe1bfcbf62bfa1d68880842c87aded09b88941
|
4
|
+
data.tar.gz: d8f0ef61f6bce1cc59d42ca4e6cedda297537d4b7183781801eb80d7e81052af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b86f6095fb35bb4273e528708380293f4a43f542d8ee790efb7d81b1c27444861139338bf5139de7a51ba0bcbc0d76228fb29625815f4690d5aa5e60e160ef7
|
7
|
+
data.tar.gz: 807ad97fa745e06a1a881c1d0318c57a6b94cf904c986da94376f546816b2125211e2a0a65ccb30e9848fedc1e58a102aa77f28f223f8d4db2f784f0a55665e8
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -17,8 +17,9 @@ class Foo
|
|
17
17
|
end
|
18
18
|
```
|
19
19
|
|
20
|
-
|
21
|
-
|
20
|
+
Unfortunately, this makes Ruby show a ‘private attribute?’ warning.
|
21
|
+
Also, I really like to declare my attribute readers and writers near
|
22
|
+
the top of my classes, which means I sometimes use something like:
|
22
23
|
|
23
24
|
```ruby
|
24
25
|
class Bar
|
@@ -56,6 +57,7 @@ class Bar
|
|
56
57
|
private_attr_accessor :foo
|
57
58
|
private_attr_reader :baz
|
58
59
|
private_attr_writer :bat
|
60
|
+
private_alias_method :bar, :foo
|
59
61
|
|
60
62
|
def initialize foo
|
61
63
|
self.foo = foo
|
@@ -79,6 +81,10 @@ class Bar
|
|
79
81
|
end
|
80
82
|
```
|
81
83
|
|
84
|
+
If you don’t want to extend all of your modules and classes
|
85
|
+
separately you can also `require 'private_attr/everywhere'`
|
86
|
+
and the methods will be available everywhere.
|
87
|
+
|
82
88
|
## Contributing
|
83
89
|
|
84
90
|
1. Fork it
|
data/lib/private_attr/version.rb
CHANGED
data/lib/private_attr.rb
CHANGED
@@ -1,35 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "private_attr/version"
|
2
4
|
|
3
5
|
module PrivateAttr
|
4
6
|
module_function
|
5
7
|
|
6
|
-
def private_attr_accessor
|
8
|
+
def private_attr_accessor(*attr)
|
7
9
|
private_attr_reader(*attr)
|
8
10
|
private_attr_writer(*attr)
|
9
11
|
end
|
10
12
|
|
11
|
-
def private_attr_reader
|
13
|
+
def private_attr_reader(*attr)
|
12
14
|
attr_reader(*attr)
|
13
15
|
private(*attr)
|
14
16
|
end
|
15
17
|
|
16
|
-
def private_attr_writer
|
18
|
+
def private_attr_writer(*attr)
|
17
19
|
attr_writer(*attr)
|
18
20
|
private(*attr.map { |a| "#{a}=" })
|
19
21
|
end
|
20
22
|
|
21
|
-
def protected_attr_accessor
|
23
|
+
def protected_attr_accessor(*attr)
|
22
24
|
protected_attr_reader(*attr)
|
23
25
|
protected_attr_writer(*attr)
|
24
26
|
end
|
25
27
|
|
26
|
-
def protected_attr_reader
|
28
|
+
def protected_attr_reader(*attr)
|
27
29
|
attr_reader(*attr)
|
28
30
|
protected(*attr)
|
29
31
|
end
|
30
32
|
|
31
|
-
def protected_attr_writer
|
33
|
+
def protected_attr_writer(*attr)
|
32
34
|
attr_writer(*attr)
|
33
35
|
protected(*attr.map { |a| "#{a}=" })
|
34
36
|
end
|
37
|
+
|
38
|
+
def private_alias_method(new_name, old_name)
|
39
|
+
alias_method(new_name, old_name)
|
40
|
+
private(new_name)
|
41
|
+
end
|
42
|
+
|
43
|
+
def protected_alias_method(new_name, old_name)
|
44
|
+
alias_method(new_name, old_name)
|
45
|
+
protected(new_name)
|
46
|
+
end
|
35
47
|
end
|
data/private_attr.gemspec
CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
|
|
18
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
|
+
gem.add_development_dependency 'bundler'
|
21
22
|
gem.add_development_dependency 'minitest', '~> 5.0'
|
22
|
-
gem.add_development_dependency 'rake', '~>
|
23
|
+
gem.add_development_dependency 'rake', '~> 12.3.3'
|
23
24
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "minitest/autorun"
|
2
|
+
|
3
|
+
describe "private_attr/everywhere" do
|
4
|
+
# these particular tests must be run in order
|
5
|
+
def self.test_order
|
6
|
+
:alpha
|
7
|
+
end
|
8
|
+
|
9
|
+
it "requiring only private_attr keeps Classes and Modules intact" do
|
10
|
+
require "private_attr"
|
11
|
+
_(Class.new.private_methods).wont_include :private_attr_reader
|
12
|
+
_(Module.new.private_methods).wont_include :private_attr_reader
|
13
|
+
end
|
14
|
+
|
15
|
+
it "requiring private_attr/everywhere adds it to all Classes and Modules" do
|
16
|
+
require "private_attr/everywhere"
|
17
|
+
_(Class.new.private_methods).must_include :private_attr_reader
|
18
|
+
_(Module.new.private_methods).must_include :private_attr_reader
|
19
|
+
end
|
20
|
+
end
|
data/spec/private_attr_spec.rb
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "minitest/autorun"
|
2
|
+
require "private_attr"
|
3
3
|
|
4
4
|
class Dummy
|
5
5
|
def read_accessor
|
6
6
|
accessor
|
7
7
|
end
|
8
8
|
|
9
|
-
def read_accessor_other
|
9
|
+
def read_accessor_other(other)
|
10
10
|
other.accessor
|
11
11
|
end
|
12
12
|
|
13
|
-
def write_accessor
|
13
|
+
def write_accessor(value)
|
14
14
|
self.accessor = value
|
15
15
|
end
|
16
16
|
|
17
|
-
def write_accessor_other
|
17
|
+
def write_accessor_other(other, value)
|
18
18
|
other.accessor = value
|
19
19
|
end
|
20
20
|
|
@@ -22,17 +22,27 @@ class Dummy
|
|
22
22
|
reader
|
23
23
|
end
|
24
24
|
|
25
|
-
def read_reader_other
|
25
|
+
def read_reader_other(other)
|
26
26
|
other.reader
|
27
27
|
end
|
28
28
|
|
29
|
-
def write_writer
|
29
|
+
def write_writer(value)
|
30
30
|
self.writer = value
|
31
31
|
end
|
32
32
|
|
33
|
-
def write_writer_other
|
33
|
+
def write_writer_other(other, value)
|
34
34
|
other.writer = value
|
35
35
|
end
|
36
|
+
|
37
|
+
attr_reader :original
|
38
|
+
|
39
|
+
def call_aliased
|
40
|
+
aliased
|
41
|
+
end
|
42
|
+
|
43
|
+
def call_aliased_other(other)
|
44
|
+
other.aliased
|
45
|
+
end
|
36
46
|
end
|
37
47
|
|
38
48
|
class PrivateDummy < Dummy
|
@@ -40,6 +50,7 @@ class PrivateDummy < Dummy
|
|
40
50
|
private_attr_accessor :accessor
|
41
51
|
private_attr_reader :reader
|
42
52
|
private_attr_writer :writer
|
53
|
+
private_alias_method :aliased, :original
|
43
54
|
end
|
44
55
|
|
45
56
|
class ProtectedDummy < Dummy
|
@@ -47,205 +58,308 @@ class ProtectedDummy < Dummy
|
|
47
58
|
protected_attr_accessor :accessor
|
48
59
|
protected_attr_reader :reader
|
49
60
|
protected_attr_writer :writer
|
61
|
+
protected_alias_method :aliased, :original
|
50
62
|
end
|
51
63
|
|
52
64
|
describe PrivateAttr do
|
53
65
|
let(:dummy) { dummy_class.new }
|
54
66
|
let(:other) { dummy_class.new }
|
55
|
-
let(:old_value) {
|
56
|
-
let(:
|
67
|
+
let(:old_value) { "old value" }
|
68
|
+
let(:new_value) { "new value" }
|
57
69
|
|
58
|
-
describe
|
70
|
+
describe "private_attr_accessor" do
|
59
71
|
let(:dummy_class) { PrivateDummy }
|
60
72
|
|
61
|
-
before { dummy.instance_variable_set
|
73
|
+
before { dummy.instance_variable_set "@accessor", old_value }
|
62
74
|
|
63
|
-
it
|
64
|
-
dummy.read_accessor.must_equal old_value
|
75
|
+
it "allows attribute to be read internally" do
|
76
|
+
_(dummy.read_accessor).must_equal old_value
|
65
77
|
end
|
66
78
|
|
67
|
-
it
|
68
|
-
dummy.write_accessor
|
69
|
-
dummy.instance_variable_get(
|
79
|
+
it "allows attribute to be written internally" do
|
80
|
+
dummy.write_accessor new_value
|
81
|
+
_(dummy.instance_variable_get("@accessor")).must_equal new_value
|
70
82
|
end
|
71
83
|
|
72
|
-
it
|
73
|
-
|
84
|
+
it "raises Error when read externally" do
|
85
|
+
_{ dummy.accessor }.must_raise NoMethodError
|
74
86
|
end
|
75
87
|
|
76
|
-
it
|
77
|
-
|
88
|
+
it "raises Error when written externally" do
|
89
|
+
_{ dummy.accessor = new_value }.must_raise NoMethodError
|
78
90
|
end
|
79
91
|
|
80
|
-
it
|
81
|
-
|
92
|
+
it "raises Error when read by other" do
|
93
|
+
_{ dummy.read_accessor_other other }.must_raise NoMethodError
|
82
94
|
end
|
83
95
|
|
84
|
-
it
|
85
|
-
|
96
|
+
it "raises Error when written by other" do
|
97
|
+
_{ dummy.write_accessor_other other, new_value }.must_raise NoMethodError
|
86
98
|
end
|
87
99
|
end
|
88
100
|
|
89
|
-
describe
|
101
|
+
describe "private_attr_reader" do
|
90
102
|
let(:dummy_class) { PrivateDummy }
|
91
103
|
|
92
|
-
before { dummy.instance_variable_set
|
104
|
+
before { dummy.instance_variable_set "@reader", old_value }
|
93
105
|
|
94
|
-
it
|
95
|
-
dummy.read_reader.must_equal old_value
|
106
|
+
it "allows attribute to be read internally" do
|
107
|
+
_(dummy.read_reader).must_equal old_value
|
96
108
|
end
|
97
109
|
|
98
|
-
it
|
99
|
-
|
110
|
+
it "raises Error when written internally" do
|
111
|
+
_{ dummy.write_reader new_value }.must_raise NoMethodError
|
100
112
|
end
|
101
113
|
|
102
|
-
it
|
103
|
-
|
114
|
+
it "raises Error when read externally" do
|
115
|
+
_{ dummy.reader }.must_raise NoMethodError
|
104
116
|
end
|
105
117
|
|
106
|
-
it
|
107
|
-
|
118
|
+
it "raises Error when written externally" do
|
119
|
+
_{ dummy.reader = new_value }.must_raise NoMethodError
|
108
120
|
end
|
109
121
|
|
110
|
-
it
|
111
|
-
|
122
|
+
it "raises Error when read by other" do
|
123
|
+
_{ dummy.read_reader_other other }.must_raise NoMethodError
|
112
124
|
end
|
113
125
|
|
114
|
-
it
|
115
|
-
|
126
|
+
it "raises Error when written by other" do
|
127
|
+
_{ dummy.write_reader_other other, new_value }.must_raise NoMethodError
|
116
128
|
end
|
117
129
|
end
|
118
130
|
|
119
|
-
describe
|
131
|
+
describe "private_attr_writer" do
|
120
132
|
let(:dummy_class) { PrivateDummy }
|
121
133
|
|
122
|
-
before { dummy.instance_variable_set
|
134
|
+
before { dummy.instance_variable_set "@writer", old_value }
|
123
135
|
|
124
|
-
it
|
125
|
-
|
136
|
+
it "raises Error when read internally" do
|
137
|
+
_{ dummy.read_writer }.must_raise NoMethodError
|
126
138
|
end
|
127
139
|
|
128
|
-
it
|
129
|
-
dummy.write_writer
|
130
|
-
dummy.instance_variable_get(
|
140
|
+
it "allows attribute to be written internally" do
|
141
|
+
dummy.write_writer new_value
|
142
|
+
_(dummy.instance_variable_get("@writer")).must_equal new_value
|
131
143
|
end
|
132
144
|
|
133
|
-
it
|
134
|
-
|
145
|
+
it "raises Error when read externally" do
|
146
|
+
_{ dummy.writer }.must_raise NoMethodError
|
135
147
|
end
|
136
148
|
|
137
|
-
it
|
138
|
-
|
149
|
+
it "raises Error when written externally" do
|
150
|
+
_{ dummy.writer = new_value }.must_raise NoMethodError
|
139
151
|
end
|
140
152
|
|
141
|
-
it
|
142
|
-
|
153
|
+
it "raises Error when read by other" do
|
154
|
+
_{ dummy.read_writer_other other }.must_raise NoMethodError
|
143
155
|
end
|
144
156
|
|
145
|
-
it
|
146
|
-
|
157
|
+
it "raises Error when written by other" do
|
158
|
+
_{ dummy.write_writer_other other, new_value }.must_raise NoMethodError
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe "private_alias_method" do
|
163
|
+
let(:dummy_class) { PrivateDummy }
|
164
|
+
|
165
|
+
before { dummy.instance_variable_set "@original", old_value }
|
166
|
+
|
167
|
+
it "allows alias to be called internally" do
|
168
|
+
_(dummy.call_aliased).must_equal old_value
|
169
|
+
end
|
170
|
+
|
171
|
+
it "raises Error when alias is called externally" do
|
172
|
+
_{ dummy.aliased other }.must_raise NoMethodError
|
173
|
+
end
|
174
|
+
|
175
|
+
it "raises Error when alias is called by other" do
|
176
|
+
_{ dummy.call_aliased_other other }.must_raise NoMethodError
|
177
|
+
end
|
178
|
+
|
179
|
+
it "allows the original method to be called externally" do
|
180
|
+
_(dummy.original).must_equal old_value
|
181
|
+
end
|
182
|
+
|
183
|
+
describe "when the original method is overridden" do
|
184
|
+
let(:dummy_class) do
|
185
|
+
mod = Module.new do
|
186
|
+
def original
|
187
|
+
super.upcase
|
188
|
+
end
|
189
|
+
end
|
190
|
+
Class.new(PrivateDummy).send(:include, mod)
|
191
|
+
end
|
192
|
+
|
193
|
+
it "allows alias to be called internally" do
|
194
|
+
_(dummy.call_aliased).must_equal old_value
|
195
|
+
end
|
196
|
+
|
197
|
+
it "raises Error when alias is called externally" do
|
198
|
+
_{ dummy.aliased }.must_raise NoMethodError
|
199
|
+
end
|
200
|
+
|
201
|
+
it "raises Error when alias is called by other" do
|
202
|
+
_{ dummy.call_aliased_other other }.must_raise NoMethodError
|
203
|
+
end
|
204
|
+
|
205
|
+
it "allows the overridden method to be called externally" do
|
206
|
+
_(dummy.original).must_equal old_value.upcase
|
207
|
+
end
|
147
208
|
end
|
148
209
|
end
|
149
210
|
|
150
|
-
describe
|
211
|
+
describe "protected_attr_accessor" do
|
151
212
|
let(:dummy_class) { ProtectedDummy }
|
152
213
|
|
153
|
-
before { dummy.instance_variable_set
|
214
|
+
before { dummy.instance_variable_set "@accessor", old_value }
|
154
215
|
|
155
|
-
it
|
156
|
-
dummy.read_accessor.must_equal old_value
|
216
|
+
it "allows attribute to be read internally" do
|
217
|
+
_(dummy.read_accessor).must_equal old_value
|
157
218
|
end
|
158
219
|
|
159
|
-
it
|
160
|
-
dummy.write_accessor
|
161
|
-
dummy.instance_variable_get(
|
220
|
+
it "allows attribute to be written internally" do
|
221
|
+
dummy.write_accessor new_value
|
222
|
+
_(dummy.instance_variable_get("@accessor")).must_equal new_value
|
162
223
|
end
|
163
224
|
|
164
|
-
it
|
165
|
-
|
225
|
+
it "raises Error when read externally" do
|
226
|
+
_{ dummy.accessor }.must_raise NoMethodError
|
166
227
|
end
|
167
228
|
|
168
|
-
it
|
169
|
-
|
229
|
+
it "raises Error when written externally" do
|
230
|
+
_{ dummy.accessor = new_value }.must_raise NoMethodError
|
170
231
|
end
|
171
232
|
|
172
|
-
it
|
173
|
-
other.instance_variable_set
|
174
|
-
dummy.read_accessor_other(other).must_equal
|
233
|
+
it "allows attribute to be read by other" do
|
234
|
+
other.instance_variable_set "@accessor", new_value
|
235
|
+
_(dummy.read_accessor_other(other)).must_equal new_value
|
175
236
|
end
|
176
237
|
|
177
|
-
it
|
178
|
-
dummy.write_accessor_other other,
|
179
|
-
other.instance_variable_get(
|
238
|
+
it "allows attribute to be written by other" do
|
239
|
+
dummy.write_accessor_other other, new_value
|
240
|
+
_(other.instance_variable_get("@accessor")).must_equal new_value
|
180
241
|
end
|
181
242
|
end
|
182
243
|
|
183
|
-
describe
|
244
|
+
describe "protected_attr_reader" do
|
184
245
|
let(:dummy_class) { ProtectedDummy }
|
185
246
|
|
186
|
-
before { dummy.instance_variable_set
|
247
|
+
before { dummy.instance_variable_set "@reader", old_value }
|
187
248
|
|
188
|
-
it
|
189
|
-
dummy.read_reader.must_equal old_value
|
249
|
+
it "allows attribute to be read internally" do
|
250
|
+
_(dummy.read_reader).must_equal old_value
|
190
251
|
end
|
191
252
|
|
192
|
-
it
|
193
|
-
|
253
|
+
it "raises Error when written internally" do
|
254
|
+
_{ dummy.write_reader new_value }.must_raise NoMethodError
|
194
255
|
end
|
195
256
|
|
196
|
-
it
|
197
|
-
|
257
|
+
it "raises Error when read externally" do
|
258
|
+
_{ dummy.reader }.must_raise NoMethodError
|
198
259
|
end
|
199
260
|
|
200
|
-
it
|
201
|
-
|
261
|
+
it "raises Error when written externally" do
|
262
|
+
_{ dummy.reader = new_value }.must_raise NoMethodError
|
202
263
|
end
|
203
264
|
|
204
|
-
it
|
205
|
-
other.instance_variable_set
|
206
|
-
dummy.read_reader_other(other).must_equal
|
265
|
+
it "allows attribute to be read by other" do
|
266
|
+
other.instance_variable_set "@reader", new_value
|
267
|
+
_(dummy.read_reader_other(other)).must_equal new_value
|
207
268
|
end
|
208
269
|
|
209
|
-
it
|
210
|
-
|
270
|
+
it "raises Error when written by other" do
|
271
|
+
_{ dummy.write_reader_other other, new_value }.must_raise NoMethodError
|
211
272
|
end
|
212
273
|
end
|
213
274
|
|
214
|
-
describe
|
275
|
+
describe "protected_attr_writer" do
|
215
276
|
let(:dummy_class) { ProtectedDummy }
|
216
277
|
|
217
|
-
before { dummy.instance_variable_set
|
278
|
+
before { dummy.instance_variable_set "@writer", old_value }
|
279
|
+
|
280
|
+
it "raises Error when read internally" do
|
281
|
+
_{ dummy.read_writer }.must_raise NoMethodError
|
282
|
+
end
|
283
|
+
|
284
|
+
it "allows attribute to be written internally" do
|
285
|
+
dummy.write_writer new_value
|
286
|
+
_(dummy.instance_variable_get("@writer")).must_equal new_value
|
287
|
+
end
|
218
288
|
|
219
|
-
it
|
220
|
-
|
289
|
+
it "raises Error when read externally" do
|
290
|
+
_{ dummy.writer }.must_raise NoMethodError
|
221
291
|
end
|
222
292
|
|
223
|
-
it
|
224
|
-
dummy.
|
225
|
-
dummy.instance_variable_get('@writer').must_equal value
|
293
|
+
it "raises Error when written externally" do
|
294
|
+
_{ dummy.writer = new_value }.must_raise NoMethodError
|
226
295
|
end
|
227
296
|
|
228
|
-
it
|
229
|
-
|
297
|
+
it "raises Error when read by other" do
|
298
|
+
_{ dummy.read_writer_other other }.must_raise NoMethodError
|
230
299
|
end
|
231
300
|
|
232
|
-
it
|
233
|
-
|
301
|
+
it "allows attribute to be written by other" do
|
302
|
+
dummy.write_writer_other other, new_value
|
303
|
+
_(other.instance_variable_get("@writer")).must_equal new_value
|
304
|
+
end
|
305
|
+
end
|
306
|
+
|
307
|
+
describe "protected_alias_method" do
|
308
|
+
let(:dummy_class) { ProtectedDummy }
|
309
|
+
let(:other_value) { "other value" }
|
310
|
+
|
311
|
+
before do
|
312
|
+
dummy.instance_variable_set "@original", old_value
|
313
|
+
other.instance_variable_set "@original", other_value
|
234
314
|
end
|
235
315
|
|
236
|
-
it
|
237
|
-
|
316
|
+
it "allows alias to be called internally" do
|
317
|
+
_(dummy.call_aliased).must_equal old_value
|
238
318
|
end
|
239
319
|
|
240
|
-
it
|
241
|
-
dummy.
|
242
|
-
|
320
|
+
it "raises Error when alias is called externally" do
|
321
|
+
_{ dummy.aliased }.must_raise NoMethodError
|
322
|
+
end
|
323
|
+
|
324
|
+
it "allows alias to be called by other" do
|
325
|
+
_(dummy.call_aliased_other(other)).must_equal other_value
|
326
|
+
end
|
327
|
+
|
328
|
+
it "allows the original method to be called externally" do
|
329
|
+
_(dummy.original).must_equal old_value
|
330
|
+
end
|
331
|
+
|
332
|
+
describe "when the original method is overridden" do
|
333
|
+
let(:dummy_class) do
|
334
|
+
mod = Module.new do
|
335
|
+
def original
|
336
|
+
super.upcase
|
337
|
+
end
|
338
|
+
end
|
339
|
+
Class.new(ProtectedDummy).send(:include, mod)
|
340
|
+
end
|
341
|
+
|
342
|
+
it "allows alias to be called internally" do
|
343
|
+
_(dummy.call_aliased).must_equal old_value
|
344
|
+
end
|
345
|
+
|
346
|
+
it "raises Error when alias is called externally" do
|
347
|
+
_{ dummy.aliased }.must_raise NoMethodError
|
348
|
+
end
|
349
|
+
|
350
|
+
it "allows alias to be called by other" do
|
351
|
+
_(dummy.call_aliased_other(other)).must_equal other_value
|
352
|
+
end
|
353
|
+
|
354
|
+
it "allows the overridden method to be called externally" do
|
355
|
+
_(dummy.original).must_equal old_value.upcase
|
356
|
+
end
|
243
357
|
end
|
244
358
|
end
|
245
359
|
|
246
|
-
describe
|
247
|
-
it
|
248
|
-
PrivateDummy.public_methods.wont_include :private_attr_accessor
|
360
|
+
describe "method visibility" do
|
361
|
+
it "extending classes does not increase their public APIs" do
|
362
|
+
_(PrivateDummy.public_methods).wont_include :private_attr_accessor
|
249
363
|
end
|
250
364
|
end
|
251
365
|
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: private_attr
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jacob Swanner
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-09-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -30,14 +44,14 @@ dependencies:
|
|
30
44
|
requirements:
|
31
45
|
- - "~>"
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 12.3.3
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: 12.3.3
|
41
55
|
description: Easily create private/protected attribute readers/writers
|
42
56
|
email:
|
43
57
|
- jacob@jacobswanner.com
|
@@ -52,14 +66,16 @@ files:
|
|
52
66
|
- README.md
|
53
67
|
- Rakefile
|
54
68
|
- lib/private_attr.rb
|
69
|
+
- lib/private_attr/everywhere.rb
|
55
70
|
- lib/private_attr/version.rb
|
56
71
|
- private_attr.gemspec
|
72
|
+
- spec/private_attr/everywhere_spec.rb
|
57
73
|
- spec/private_attr_spec.rb
|
58
74
|
homepage: https://github.com/jswanner/private_attr
|
59
75
|
licenses:
|
60
76
|
- MIT
|
61
77
|
metadata: {}
|
62
|
-
post_install_message:
|
78
|
+
post_install_message:
|
63
79
|
rdoc_options: []
|
64
80
|
require_paths:
|
65
81
|
- lib
|
@@ -74,11 +90,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
90
|
- !ruby/object:Gem::Version
|
75
91
|
version: '0'
|
76
92
|
requirements: []
|
77
|
-
|
78
|
-
|
79
|
-
signing_key:
|
93
|
+
rubygems_version: 3.2.31
|
94
|
+
signing_key:
|
80
95
|
specification_version: 4
|
81
96
|
summary: Easily create private/protected attribute readers/writers
|
82
97
|
test_files:
|
98
|
+
- spec/private_attr/everywhere_spec.rb
|
83
99
|
- spec/private_attr_spec.rb
|
84
|
-
has_rdoc:
|