ruby-enum 0.9.0 → 1.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 +4 -4
- data/CHANGELOG.md +14 -0
- data/Dangerfile +2 -0
- data/Gemfile +8 -5
- data/Gemfile.lock +147 -82
- data/README.md +61 -2
- data/Rakefile +7 -0
- data/benchmarks/case.rb +45 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc_disabled.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_both.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc.png +0 -0
- data/coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc_disabled.png +0 -0
- data/coverage/assets/0.13.2/application.css +1 -0
- data/coverage/assets/0.13.2/application.js +7 -0
- data/coverage/assets/0.13.2/colorbox/border.png +0 -0
- data/coverage/assets/0.13.2/colorbox/controls.png +0 -0
- data/coverage/assets/0.13.2/colorbox/loading.gif +0 -0
- data/coverage/assets/0.13.2/colorbox/loading_background.png +0 -0
- data/coverage/assets/0.13.2/favicon_green.png +0 -0
- data/coverage/assets/0.13.2/favicon_red.png +0 -0
- data/coverage/assets/0.13.2/favicon_yellow.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/coverage/assets/0.13.2/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_222222_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_2e83ff_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_454545_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_888888_256x240.png +0 -0
- data/coverage/assets/0.13.2/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/coverage/assets/0.13.2/loading.gif +0 -0
- data/coverage/assets/0.13.2/magnify.png +0 -0
- data/coverage/index.html +5768 -973
- data/lib/ruby-enum/enum/case.rb +84 -0
- data/lib/ruby-enum/enum/i18n_mock.rb +19 -0
- data/lib/ruby-enum/enum.rb +9 -3
- data/lib/ruby-enum/errors/base.rb +4 -4
- data/lib/ruby-enum/version.rb +1 -1
- data/lib/ruby-enum.rb +15 -3
- data/pkg/ruby-enum-0.9.0.gem +0 -0
- data/ruby-enum.gemspec +2 -1
- data/spec/ruby-enum/enum/case_spec.rb +119 -0
- data/spec/ruby-enum/enum_spec.rb +201 -71
- data/spec/spec_helper.rb +2 -2
- data/spec_i18n/Gemfile +9 -0
- data/spec_i18n/Rakefile +12 -0
- data/spec_i18n/spec/i18n_spec.rb +50 -0
- data/spec_i18n/spec/spec_helper.rb +8 -0
- metadata +45 -20
data/spec/ruby-enum/enum_spec.rb
CHANGED
|
@@ -2,30 +2,54 @@
|
|
|
2
2
|
|
|
3
3
|
require 'spec_helper'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
describe Ruby::Enum do
|
|
6
|
+
class Colors
|
|
7
|
+
include Ruby::Enum
|
|
7
8
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
end
|
|
9
|
+
define :RED, 'red'
|
|
10
|
+
define :GREEN, 'green'
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
class FirstSubclass < Colors
|
|
13
|
-
|
|
14
|
-
end
|
|
13
|
+
class FirstSubclass < Colors
|
|
14
|
+
define :ORANGE, 'orange'
|
|
15
|
+
end
|
|
15
16
|
|
|
16
|
-
class SecondSubclass < FirstSubclass
|
|
17
|
-
|
|
18
|
-
end
|
|
17
|
+
class SecondSubclass < FirstSubclass
|
|
18
|
+
define :PINK, 'pink'
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class OtherSecondSubclass < FirstSubclass
|
|
22
|
+
include Ruby::Enum
|
|
23
|
+
|
|
24
|
+
define :MAGENTA, 'magenta'
|
|
25
|
+
end
|
|
19
26
|
|
|
20
|
-
describe Ruby::Enum do
|
|
21
27
|
it 'returns an enum value' do
|
|
22
28
|
expect(Colors::RED).to eq 'red'
|
|
23
29
|
expect(Colors::GREEN).to eq 'green'
|
|
24
30
|
end
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
context 'when the i18n gem is loaded' do
|
|
33
|
+
it 'raises UninitializedConstantError on an invalid constant' do
|
|
34
|
+
expect do
|
|
35
|
+
Colors::ANYTHING
|
|
36
|
+
end.to raise_error Ruby::Enum::Errors::UninitializedConstantError, /The constant Colors::ANYTHING has not been defined./
|
|
37
|
+
end
|
|
27
38
|
end
|
|
28
|
-
|
|
39
|
+
|
|
40
|
+
context 'when the i18n gem is not loaded' do
|
|
41
|
+
before do
|
|
42
|
+
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'raises UninitializedConstantError on an invalid constant' do
|
|
46
|
+
expect do
|
|
47
|
+
Colors::ANYTHING
|
|
48
|
+
end.to raise_error Ruby::Enum::Errors::UninitializedConstantError, /ruby.enum.errors.messages.uninitialized_constant.summary/
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
describe '#each' do
|
|
29
53
|
it 'iterates over constants' do
|
|
30
54
|
keys = []
|
|
31
55
|
enum_keys = []
|
|
@@ -40,7 +64,8 @@ describe Ruby::Enum do
|
|
|
40
64
|
expect(enum_values).to eq %w[red green]
|
|
41
65
|
end
|
|
42
66
|
end
|
|
43
|
-
|
|
67
|
+
|
|
68
|
+
describe '#map' do
|
|
44
69
|
it 'maps constants' do
|
|
45
70
|
key_key_values = Colors.map do |key, enum|
|
|
46
71
|
[key, enum.key, enum.value]
|
|
@@ -50,103 +75,211 @@ describe Ruby::Enum do
|
|
|
50
75
|
expect(key_key_values[1]).to eq [:GREEN, :GREEN, 'green']
|
|
51
76
|
end
|
|
52
77
|
end
|
|
53
|
-
|
|
78
|
+
|
|
79
|
+
describe '#parse' do
|
|
54
80
|
it 'parses exact value' do
|
|
55
81
|
expect(Colors.parse('red')).to eq(Colors::RED)
|
|
56
82
|
end
|
|
83
|
+
|
|
57
84
|
it 'is case-insensitive' do
|
|
58
85
|
expect(Colors.parse('ReD')).to eq(Colors::RED)
|
|
59
86
|
end
|
|
87
|
+
|
|
60
88
|
it 'returns nil for a null value' do
|
|
61
89
|
expect(Colors.parse(nil)).to be_nil
|
|
62
90
|
end
|
|
91
|
+
|
|
63
92
|
it 'returns nil for an invalid value' do
|
|
64
93
|
expect(Colors.parse('invalid')).to be_nil
|
|
65
94
|
end
|
|
66
95
|
end
|
|
67
|
-
|
|
96
|
+
|
|
97
|
+
describe '#key?' do
|
|
68
98
|
it 'returns true for valid keys accessed directly' do
|
|
69
99
|
Colors.keys.each do |key| # rubocop:disable Style/HashEachMethods
|
|
70
|
-
expect(Colors.key?(key)).to
|
|
100
|
+
expect(Colors.key?(key)).to be(true)
|
|
71
101
|
end
|
|
72
102
|
end
|
|
103
|
+
|
|
73
104
|
it 'returns true for valid keys accessed via each_keys' do
|
|
74
105
|
Colors.each_key do |key|
|
|
75
|
-
expect(Colors.key?(key)).to
|
|
106
|
+
expect(Colors.key?(key)).to be(true)
|
|
76
107
|
end
|
|
77
108
|
end
|
|
109
|
+
|
|
78
110
|
it 'returns false for invalid keys' do
|
|
79
|
-
expect(Colors.key?(:NOT_A_KEY)).to
|
|
111
|
+
expect(Colors.key?(:NOT_A_KEY)).to be(false)
|
|
80
112
|
end
|
|
81
113
|
end
|
|
82
|
-
|
|
114
|
+
|
|
115
|
+
describe '#value' do
|
|
83
116
|
it 'returns string values for keys' do
|
|
84
117
|
Colors.each do |key, enum|
|
|
85
118
|
expect(Colors.value(key)).to eq(enum.value)
|
|
86
119
|
end
|
|
87
120
|
end
|
|
121
|
+
|
|
88
122
|
it 'returns nil for an invalid key' do
|
|
89
123
|
expect(Colors.value(:NOT_A_KEY)).to be_nil
|
|
90
124
|
end
|
|
91
125
|
end
|
|
92
|
-
|
|
126
|
+
|
|
127
|
+
describe '#value?' do
|
|
93
128
|
it 'returns true for valid values accessed directly' do
|
|
94
129
|
Colors.values.each do |value| # rubocop:disable Style/HashEachMethods
|
|
95
|
-
expect(Colors.value?(value)).to
|
|
130
|
+
expect(Colors.value?(value)).to be(true)
|
|
96
131
|
end
|
|
97
132
|
end
|
|
133
|
+
|
|
98
134
|
it 'returns true for valid values accessed via each_value' do
|
|
99
135
|
Colors.each_value do |value|
|
|
100
|
-
expect(Colors.value?(value)).to
|
|
136
|
+
expect(Colors.value?(value)).to be(true)
|
|
101
137
|
end
|
|
102
138
|
end
|
|
139
|
+
|
|
103
140
|
it 'returns false for invalid values' do
|
|
104
|
-
expect(Colors.value?('I am not a value')).to
|
|
141
|
+
expect(Colors.value?('I am not a value')).to be(false)
|
|
105
142
|
end
|
|
106
143
|
end
|
|
107
|
-
|
|
144
|
+
|
|
145
|
+
describe '#key' do
|
|
108
146
|
it 'returns enum instances for values' do
|
|
109
|
-
Colors.each do |_, enum|
|
|
147
|
+
Colors.each do |_, enum| # rubocop:disable Style/HashEachMethods
|
|
110
148
|
expect(Colors.key(enum.value)).to eq(enum.key)
|
|
111
149
|
end
|
|
112
150
|
end
|
|
151
|
+
|
|
113
152
|
it 'returns nil for an invalid value' do
|
|
114
153
|
expect(Colors.key('invalid')).to be_nil
|
|
115
154
|
end
|
|
116
155
|
end
|
|
117
|
-
|
|
156
|
+
|
|
157
|
+
describe '#keys' do
|
|
118
158
|
it 'returns keys' do
|
|
119
159
|
expect(Colors.keys).to eq(%i[RED GREEN])
|
|
120
160
|
end
|
|
121
161
|
end
|
|
122
|
-
|
|
162
|
+
|
|
163
|
+
describe '#values' do
|
|
123
164
|
it 'returns values' do
|
|
124
165
|
expect(Colors.values).to eq(%w[red green])
|
|
125
166
|
end
|
|
167
|
+
|
|
168
|
+
context 'when a subclass is defined' do
|
|
169
|
+
it 'returns all values' do
|
|
170
|
+
expect(FirstSubclass.values).to eq(%w[red green orange])
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
context 'when a subclass of a subclass is defined' do
|
|
175
|
+
it 'returns all values' do
|
|
176
|
+
expect(SecondSubclass.values).to eq(%w[red green orange pink])
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
context 'when a subclass of a subclass is defined with redundant module inclusion' do
|
|
181
|
+
it 'returns all values' do
|
|
182
|
+
expect(OtherSecondSubclass.values).to eq(%w[red green orange magenta])
|
|
183
|
+
end
|
|
184
|
+
end
|
|
126
185
|
end
|
|
127
|
-
|
|
186
|
+
|
|
187
|
+
describe '#to_h' do
|
|
128
188
|
it 'returns a hash of key:values' do
|
|
129
189
|
expect(Colors.to_h).to eq(RED: 'red', GREEN: 'green')
|
|
130
190
|
end
|
|
131
191
|
end
|
|
132
192
|
|
|
133
|
-
context '
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
193
|
+
context 'when a duplicate key is used' do
|
|
194
|
+
context 'when the i18n gem is loaded' do
|
|
195
|
+
it 'raises DuplicateKeyError' do
|
|
196
|
+
expect do
|
|
197
|
+
Colors.class_eval do
|
|
198
|
+
define :RED, 'some'
|
|
199
|
+
end
|
|
200
|
+
end.to raise_error Ruby::Enum::Errors::DuplicateKeyError, /The constant Colors::RED has already been defined./
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
context 'when the i18n gem is not loaded' do
|
|
205
|
+
before do
|
|
206
|
+
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock)
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
it 'raises DuplicateKeyError' do
|
|
210
|
+
expect do
|
|
211
|
+
Colors.class_eval do
|
|
212
|
+
define :RED, 'some'
|
|
213
|
+
end
|
|
214
|
+
end.to raise_error Ruby::Enum::Errors::DuplicateKeyError, /ruby.enum.errors.messages.duplicate_key.message/
|
|
215
|
+
end
|
|
140
216
|
end
|
|
141
217
|
end
|
|
142
218
|
|
|
143
|
-
context '
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
219
|
+
context 'when a duplicate value is used' do
|
|
220
|
+
context 'when the i18n gem is loaded' do
|
|
221
|
+
it 'raises a DuplicateValueError' do
|
|
222
|
+
expect do
|
|
223
|
+
Colors.class_eval do
|
|
224
|
+
define :Other, 'red'
|
|
225
|
+
end
|
|
226
|
+
end.to raise_error Ruby::Enum::Errors::DuplicateValueError, /The value red has already been defined./
|
|
227
|
+
end
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
context 'when the i18n gem is not loaded' do
|
|
231
|
+
before do
|
|
232
|
+
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock)
|
|
233
|
+
end
|
|
234
|
+
|
|
235
|
+
it 'raises a DuplicateValueError' do
|
|
236
|
+
expect do
|
|
237
|
+
Colors.class_eval do
|
|
238
|
+
define :Other, 'red'
|
|
239
|
+
end
|
|
240
|
+
end.to raise_error Ruby::Enum::Errors::DuplicateValueError, /ruby.enum.errors.messages.duplicate_value.summary/
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
|
|
245
|
+
describe 'Reloading enum definition' do
|
|
246
|
+
it 'can be lazy reloaded' do
|
|
247
|
+
class_body = proc do
|
|
248
|
+
include Ruby::Enum
|
|
249
|
+
|
|
250
|
+
define :BUZZ_CUT, 'buzz_cut'
|
|
251
|
+
end
|
|
252
|
+
|
|
253
|
+
hair_styles = Class.new(&class_body)
|
|
254
|
+
|
|
255
|
+
expect { hair_styles.class_eval(&class_body) }.not_to raise_error
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
context 'when a subclass is defined' do
|
|
259
|
+
it 'NEEDS to include Ruby::Enum explicitly to be lazy reloaded' do
|
|
260
|
+
hair_styles = Class.new do
|
|
261
|
+
include Ruby::Enum
|
|
262
|
+
|
|
263
|
+
define :BUZZ_CUT, 'buzz_cut'
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
broken_subclass_body = proc do
|
|
267
|
+
define :PONYTAIL, 'ponytail'
|
|
268
|
+
end
|
|
269
|
+
broken_subclass = Class.new(hair_styles, &broken_subclass_body)
|
|
270
|
+
expect { broken_subclass.class_eval(&broken_subclass_body) }
|
|
271
|
+
.to raise_error Ruby::Enum::Errors::DuplicateKeyError, /PONYTAIL/
|
|
272
|
+
|
|
273
|
+
subclass_body = proc do
|
|
274
|
+
include Ruby::Enum
|
|
275
|
+
|
|
276
|
+
define :PONYTAIL, 'ponytail'
|
|
148
277
|
end
|
|
149
|
-
|
|
278
|
+
more_hair_styles = Class.new(hair_styles, &subclass_body)
|
|
279
|
+
|
|
280
|
+
expect { more_hair_styles.class_eval(&subclass_body) }.not_to raise_error
|
|
281
|
+
expect(more_hair_styles.values).to eq(%w[buzz_cut ponytail])
|
|
282
|
+
end
|
|
150
283
|
end
|
|
151
284
|
end
|
|
152
285
|
|
|
@@ -176,32 +309,29 @@ describe Ruby::Enum do
|
|
|
176
309
|
it 'contains its own enums' do
|
|
177
310
|
expect(FirstSubclass::ORANGE).to eq 'orange'
|
|
178
311
|
end
|
|
312
|
+
|
|
179
313
|
it 'parent class should not have enums defined in child classes' do
|
|
180
314
|
expect { Colors::ORANGE }.to raise_error Ruby::Enum::Errors::UninitializedConstantError
|
|
181
315
|
end
|
|
182
|
-
|
|
183
|
-
|
|
316
|
+
|
|
317
|
+
context 'when defining a 2 level depth subclass' do
|
|
184
318
|
it 'contains its own enums and all the enums defined in the parent classes' do
|
|
185
|
-
expect(
|
|
186
|
-
expect(
|
|
187
|
-
expect(
|
|
188
|
-
expect(
|
|
319
|
+
expect(SecondSubclass::RED).to eq 'red'
|
|
320
|
+
expect(SecondSubclass::GREEN).to eq 'green'
|
|
321
|
+
expect(SecondSubclass::ORANGE).to eq 'orange'
|
|
322
|
+
expect(SecondSubclass::PINK).to eq 'pink'
|
|
189
323
|
end
|
|
190
324
|
|
|
191
325
|
describe '#values' do
|
|
192
|
-
subject { SecondSubclass.values }
|
|
193
|
-
|
|
194
326
|
it 'contains the values from all of the parent classes' do
|
|
195
|
-
expect(
|
|
327
|
+
expect(SecondSubclass.values).to eq(%w[red green orange pink])
|
|
196
328
|
end
|
|
197
329
|
end
|
|
198
330
|
end
|
|
199
331
|
|
|
200
332
|
describe '#values' do
|
|
201
|
-
subject { FirstSubclass.values }
|
|
202
|
-
|
|
203
333
|
it 'contains the values from the parent class' do
|
|
204
|
-
expect(
|
|
334
|
+
expect(FirstSubclass.values).to eq(%w[red green orange])
|
|
205
335
|
end
|
|
206
336
|
end
|
|
207
337
|
end
|
|
@@ -209,40 +339,40 @@ describe Ruby::Enum do
|
|
|
209
339
|
describe 'default value' do
|
|
210
340
|
class Default
|
|
211
341
|
include Ruby::Enum
|
|
342
|
+
|
|
212
343
|
define :KEY
|
|
213
344
|
end
|
|
214
345
|
|
|
215
|
-
subject { Default::KEY }
|
|
216
|
-
|
|
217
346
|
it 'equals the key' do
|
|
218
|
-
expect(
|
|
347
|
+
expect(Default::KEY).to eq(:KEY)
|
|
219
348
|
end
|
|
220
349
|
end
|
|
221
350
|
|
|
222
351
|
describe 'non constant definitions' do
|
|
223
352
|
class States
|
|
224
353
|
include Ruby::Enum
|
|
354
|
+
|
|
225
355
|
define :created, 'Created'
|
|
226
356
|
define :published, 'Published'
|
|
227
357
|
define :undefined
|
|
228
358
|
end
|
|
229
|
-
|
|
359
|
+
|
|
230
360
|
it 'behaves like an enum' do
|
|
231
|
-
expect(
|
|
232
|
-
expect(
|
|
233
|
-
expect(
|
|
361
|
+
expect(States.created).to eq 'Created'
|
|
362
|
+
expect(States.published).to eq 'Published'
|
|
363
|
+
expect(States.undefined).to eq :undefined
|
|
234
364
|
|
|
235
|
-
expect(
|
|
236
|
-
expect(
|
|
365
|
+
expect(States.key?(:created)).to be true
|
|
366
|
+
expect(States.key('Created')).to eq :created
|
|
237
367
|
|
|
238
|
-
expect(
|
|
239
|
-
expect(
|
|
368
|
+
expect(States.value?('Created')).to be true
|
|
369
|
+
expect(States.value(:created)).to eq 'Created'
|
|
240
370
|
|
|
241
|
-
expect(
|
|
242
|
-
expect(
|
|
371
|
+
expect(States.key?(:undefined)).to be true
|
|
372
|
+
expect(States.key(:undefined)).to eq :undefined
|
|
243
373
|
|
|
244
|
-
expect(
|
|
245
|
-
expect(
|
|
374
|
+
expect(States.value?(:undefined)).to be true
|
|
375
|
+
expect(States.value(:undefined)).to eq :undefined
|
|
246
376
|
end
|
|
247
377
|
end
|
|
248
378
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec_i18n/Gemfile
ADDED
data/spec_i18n/Rakefile
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper'
|
|
4
|
+
|
|
5
|
+
module I18n
|
|
6
|
+
class Colors
|
|
7
|
+
include Ruby::Enum
|
|
8
|
+
|
|
9
|
+
define :RED, 'red'
|
|
10
|
+
define :GREEN, 'green'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
describe Ruby::Enum do
|
|
15
|
+
context 'when the i18n gem is not loaded' do
|
|
16
|
+
it 'raises UninitializedConstantError on an invalid constant' do
|
|
17
|
+
expect do
|
|
18
|
+
I18n::Colors::ANYTHING
|
|
19
|
+
end.to raise_error Ruby::Enum::Errors::UninitializedConstantError, /ruby.enum.errors.messages.uninitialized_constant.summary/
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when a duplicate key is used' do
|
|
23
|
+
before do
|
|
24
|
+
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'raises DuplicateKeyError' do
|
|
28
|
+
expect do
|
|
29
|
+
I18n::Colors.class_eval do
|
|
30
|
+
define :RED, 'some'
|
|
31
|
+
end
|
|
32
|
+
end.to raise_error Ruby::Enum::Errors::DuplicateKeyError, /ruby.enum.errors.messages.duplicate_key.message/
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
context 'when a duplicate value is used' do
|
|
37
|
+
before do
|
|
38
|
+
allow(described_class).to receive(:i18n).and_return(Ruby::Enum::I18nMock)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it 'raises a DuplicateValueError' do
|
|
42
|
+
expect do
|
|
43
|
+
I18n::Colors.class_eval do
|
|
44
|
+
define :Other, 'red'
|
|
45
|
+
end
|
|
46
|
+
end.to raise_error Ruby::Enum::Errors::DuplicateValueError, /ruby.enum.errors.messages.duplicate_value.summary/
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
metadata
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ruby-enum
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel Doubrovkine
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
12
|
-
dependencies:
|
|
13
|
-
- !ruby/object:Gem::Dependency
|
|
14
|
-
name: i18n
|
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
|
16
|
-
requirements:
|
|
17
|
-
- - ">="
|
|
18
|
-
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0'
|
|
20
|
-
type: :runtime
|
|
21
|
-
prerelease: false
|
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
-
requirements:
|
|
24
|
-
- - ">="
|
|
25
|
-
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0'
|
|
11
|
+
date: 2026-06-20 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
27
13
|
description:
|
|
28
14
|
email: dblock@dblock.org
|
|
29
15
|
executables: []
|
|
@@ -40,6 +26,7 @@ files:
|
|
|
40
26
|
- RELEASING.md
|
|
41
27
|
- Rakefile
|
|
42
28
|
- UPGRADING.md
|
|
29
|
+
- benchmarks/case.rb
|
|
43
30
|
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc.png
|
|
44
31
|
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_asc_disabled.png
|
|
45
32
|
- coverage/assets/0.12.3/DataTables-1.10.20/images/sort_both.png
|
|
@@ -69,10 +56,41 @@ files:
|
|
|
69
56
|
- coverage/assets/0.12.3/images/ui-icons_cd0a0a_256x240.png
|
|
70
57
|
- coverage/assets/0.12.3/loading.gif
|
|
71
58
|
- coverage/assets/0.12.3/magnify.png
|
|
59
|
+
- coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc.png
|
|
60
|
+
- coverage/assets/0.13.2/DataTables-1.10.20/images/sort_asc_disabled.png
|
|
61
|
+
- coverage/assets/0.13.2/DataTables-1.10.20/images/sort_both.png
|
|
62
|
+
- coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc.png
|
|
63
|
+
- coverage/assets/0.13.2/DataTables-1.10.20/images/sort_desc_disabled.png
|
|
64
|
+
- coverage/assets/0.13.2/application.css
|
|
65
|
+
- coverage/assets/0.13.2/application.js
|
|
66
|
+
- coverage/assets/0.13.2/colorbox/border.png
|
|
67
|
+
- coverage/assets/0.13.2/colorbox/controls.png
|
|
68
|
+
- coverage/assets/0.13.2/colorbox/loading.gif
|
|
69
|
+
- coverage/assets/0.13.2/colorbox/loading_background.png
|
|
70
|
+
- coverage/assets/0.13.2/favicon_green.png
|
|
71
|
+
- coverage/assets/0.13.2/favicon_red.png
|
|
72
|
+
- coverage/assets/0.13.2/favicon_yellow.png
|
|
73
|
+
- coverage/assets/0.13.2/images/ui-bg_flat_0_aaaaaa_40x100.png
|
|
74
|
+
- coverage/assets/0.13.2/images/ui-bg_flat_75_ffffff_40x100.png
|
|
75
|
+
- coverage/assets/0.13.2/images/ui-bg_glass_55_fbf9ee_1x400.png
|
|
76
|
+
- coverage/assets/0.13.2/images/ui-bg_glass_65_ffffff_1x400.png
|
|
77
|
+
- coverage/assets/0.13.2/images/ui-bg_glass_75_dadada_1x400.png
|
|
78
|
+
- coverage/assets/0.13.2/images/ui-bg_glass_75_e6e6e6_1x400.png
|
|
79
|
+
- coverage/assets/0.13.2/images/ui-bg_glass_95_fef1ec_1x400.png
|
|
80
|
+
- coverage/assets/0.13.2/images/ui-bg_highlight-soft_75_cccccc_1x100.png
|
|
81
|
+
- coverage/assets/0.13.2/images/ui-icons_222222_256x240.png
|
|
82
|
+
- coverage/assets/0.13.2/images/ui-icons_2e83ff_256x240.png
|
|
83
|
+
- coverage/assets/0.13.2/images/ui-icons_454545_256x240.png
|
|
84
|
+
- coverage/assets/0.13.2/images/ui-icons_888888_256x240.png
|
|
85
|
+
- coverage/assets/0.13.2/images/ui-icons_cd0a0a_256x240.png
|
|
86
|
+
- coverage/assets/0.13.2/loading.gif
|
|
87
|
+
- coverage/assets/0.13.2/magnify.png
|
|
72
88
|
- coverage/index.html
|
|
73
89
|
- lib/config/locales/en.yml
|
|
74
90
|
- lib/ruby-enum.rb
|
|
75
91
|
- lib/ruby-enum/enum.rb
|
|
92
|
+
- lib/ruby-enum/enum/case.rb
|
|
93
|
+
- lib/ruby-enum/enum/i18n_mock.rb
|
|
76
94
|
- lib/ruby-enum/errors/base.rb
|
|
77
95
|
- lib/ruby-enum/errors/duplicate_key_error.rb
|
|
78
96
|
- lib/ruby-enum/errors/duplicate_value_error.rb
|
|
@@ -80,14 +98,21 @@ files:
|
|
|
80
98
|
- lib/ruby-enum/version.rb
|
|
81
99
|
- lib/ruby_enum.rb
|
|
82
100
|
- pkg/ruby-enum-0.8.0.gem
|
|
101
|
+
- pkg/ruby-enum-0.9.0.gem
|
|
83
102
|
- ruby-enum.gemspec
|
|
103
|
+
- spec/ruby-enum/enum/case_spec.rb
|
|
84
104
|
- spec/ruby-enum/enum_spec.rb
|
|
85
105
|
- spec/ruby-enum/version_spec.rb
|
|
86
106
|
- spec/spec_helper.rb
|
|
107
|
+
- spec_i18n/Gemfile
|
|
108
|
+
- spec_i18n/Rakefile
|
|
109
|
+
- spec_i18n/spec/i18n_spec.rb
|
|
110
|
+
- spec_i18n/spec/spec_helper.rb
|
|
87
111
|
homepage: http://github.com/dblock/ruby-enum
|
|
88
112
|
licenses:
|
|
89
113
|
- MIT
|
|
90
|
-
metadata:
|
|
114
|
+
metadata:
|
|
115
|
+
rubygems_mfa_required: 'true'
|
|
91
116
|
post_install_message:
|
|
92
117
|
rdoc_options: []
|
|
93
118
|
require_paths:
|
|
@@ -96,14 +121,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
96
121
|
requirements:
|
|
97
122
|
- - ">="
|
|
98
123
|
- !ruby/object:Gem::Version
|
|
99
|
-
version: '
|
|
124
|
+
version: '2.7'
|
|
100
125
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
101
126
|
requirements:
|
|
102
127
|
- - ">="
|
|
103
128
|
- !ruby/object:Gem::Version
|
|
104
129
|
version: 1.3.6
|
|
105
130
|
requirements: []
|
|
106
|
-
rubygems_version: 3.
|
|
131
|
+
rubygems_version: 3.5.16
|
|
107
132
|
signing_key:
|
|
108
133
|
specification_version: 4
|
|
109
134
|
summary: Enum-like behavior for Ruby.
|