enumerate_it 3.3.0 → 4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +0 -43
- data/.rubocop.yml +1 -1
- data/Appraisals +2 -13
- data/Gemfile.lock +5 -5
- data/README.md +105 -77
- data/enumerate_it.gemspec +2 -2
- data/lib/enumerate_it/version.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- metadata +6 -9
- data/gemfiles/rails_5.0.gemfile +0 -9
- data/gemfiles/rails_5.1.gemfile +0 -9
- data/gemfiles/rails_5.2.gemfile +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57b418cb6e9cf24f8b935c898004ddc62ba373f9c03b4c3df600339a26e7d16e
|
4
|
+
data.tar.gz: 4625233483bf656e0e75d9d116dff98fb1801f31e348c54e643bd501081da1fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: af19adb823775b00e138df51023b4a724219e9c12958218fb63cbea843fecb0ce8a97657a3ec6aceca2d2db4818b9415c6a94f5105bb31dbca415b542acf3158
|
7
|
+
data.tar.gz: bbaab168f1ba3c5199eced5b46244dae3499b459a8941d9719a3f264cc5a08d46c2d5356aae9381a686c46bce0cc43df6a4230ae2e4fe8266f4bb5a8335ae708
|
data/.github/workflows/ci.yml
CHANGED
@@ -9,58 +9,15 @@ jobs:
|
|
9
9
|
|
10
10
|
matrix:
|
11
11
|
ruby:
|
12
|
-
- 2.5
|
13
|
-
- 2.6
|
14
|
-
- 2.7
|
15
12
|
- 3.0
|
16
13
|
- 3.1
|
17
14
|
- 3.2
|
18
15
|
- 3.3
|
19
16
|
gemfile:
|
20
|
-
- gemfiles/rails_5.0.gemfile
|
21
|
-
- gemfiles/rails_5.1.gemfile
|
22
|
-
- gemfiles/rails_5.2.gemfile
|
23
17
|
- gemfiles/rails_6.0.gemfile
|
24
18
|
- gemfiles/rails_6.1.gemfile
|
25
19
|
- gemfiles/rails_7.0.gemfile
|
26
20
|
- gemfiles/rails_7.1.gemfile
|
27
|
-
exclude:
|
28
|
-
# Rails < 6 does not support Ruby 3+:
|
29
|
-
# https://github.com/rails/rails/issues/40938#issuecomment-751357907
|
30
|
-
- ruby: 3.0
|
31
|
-
gemfile: gemfiles/rails_5.0.gemfile
|
32
|
-
- ruby: 3.0
|
33
|
-
gemfile: gemfiles/rails_5.1.gemfile
|
34
|
-
- ruby: 3.0
|
35
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
36
|
-
- ruby: 3.1
|
37
|
-
gemfile: gemfiles/rails_5.0.gemfile
|
38
|
-
- ruby: 3.1
|
39
|
-
gemfile: gemfiles/rails_5.1.gemfile
|
40
|
-
- ruby: 3.1
|
41
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
42
|
-
- ruby: 3.2
|
43
|
-
gemfile: gemfiles/rails_5.0.gemfile
|
44
|
-
- ruby: 3.2
|
45
|
-
gemfile: gemfiles/rails_5.1.gemfile
|
46
|
-
- ruby: 3.2
|
47
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
48
|
-
- ruby: 3.3
|
49
|
-
gemfile: gemfiles/rails_5.0.gemfile
|
50
|
-
- ruby: 3.3
|
51
|
-
gemfile: gemfiles/rails_5.1.gemfile
|
52
|
-
- ruby: 3.3
|
53
|
-
gemfile: gemfiles/rails_5.2.gemfile
|
54
|
-
|
55
|
-
# Rails 7.x requires Ruby 2.7+
|
56
|
-
- ruby: 2.5
|
57
|
-
gemfile: gemfiles/rails_7.0.gemfile
|
58
|
-
- ruby: 2.5
|
59
|
-
gemfile: gemfiles/rails_7.1.gemfile
|
60
|
-
- ruby: 2.6
|
61
|
-
gemfile: gemfiles/rails_7.0.gemfile
|
62
|
-
- ruby: 2.6
|
63
|
-
gemfile: gemfiles/rails_7.1.gemfile
|
64
21
|
|
65
22
|
env:
|
66
23
|
BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
|
data/.rubocop.yml
CHANGED
data/Appraisals
CHANGED
@@ -4,7 +4,7 @@ require 'json'
|
|
4
4
|
rails_versions = JSON.parse(Net::HTTP.get(URI('https://rubygems.org/api/v1/versions/rails.json')))
|
5
5
|
.group_by { |version| version['number'] }.keys.grep_v(/rc|racecar|beta|pre/)
|
6
6
|
|
7
|
-
%w[
|
7
|
+
%w[6.0 6.1 7.0 7.1].each do |rails_version|
|
8
8
|
appraise "rails_#{rails_version}" do
|
9
9
|
current_version = rails_versions
|
10
10
|
.select { |key| key.match(/\A#{rails_version}/) }
|
@@ -13,17 +13,6 @@ rails_versions = JSON.parse(Net::HTTP.get(URI('https://rubygems.org/api/v1/versi
|
|
13
13
|
gem 'activesupport', "~> #{current_version}"
|
14
14
|
gem 'activerecord', "~> #{current_version}"
|
15
15
|
|
16
|
-
|
17
|
-
gem 'sqlite3', '< 1.4'
|
18
|
-
else
|
19
|
-
# v2.x isn't yet working. See: https://github.com/sparklemotion/sqlite3-ruby/issues/529
|
20
|
-
gem 'sqlite3', '< 2'
|
21
|
-
end
|
22
|
-
|
23
|
-
# elsif Gem::Version.new(RUBY_VERSION) < '3'
|
24
|
-
# gem 'sqlite3', '< 2'
|
25
|
-
# else
|
26
|
-
# gem 'sqlite3'
|
27
|
-
# end
|
16
|
+
gem 'sqlite3', '< 2' # v2.x isn't yet working. See: https://github.com/sparklemotion/sqlite3-ruby/issues/529
|
28
17
|
end
|
29
18
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
enumerate_it (
|
5
|
-
activesupport (>=
|
4
|
+
enumerate_it (4.0.0)
|
5
|
+
activesupport (>= 6.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -44,7 +44,7 @@ GEM
|
|
44
44
|
minitest (5.22.3)
|
45
45
|
mutex_m (0.2.0)
|
46
46
|
parallel (1.24.0)
|
47
|
-
parser (3.3.0
|
47
|
+
parser (3.3.1.0)
|
48
48
|
ast (~> 2.4.1)
|
49
49
|
racc
|
50
50
|
pry (0.14.2)
|
@@ -68,7 +68,7 @@ GEM
|
|
68
68
|
diff-lcs (>= 1.2.0, < 2.0)
|
69
69
|
rspec-support (~> 3.13.0)
|
70
70
|
rspec-support (3.13.1)
|
71
|
-
rubocop (1.63.
|
71
|
+
rubocop (1.63.3)
|
72
72
|
json (~> 2.3)
|
73
73
|
language_server-protocol (>= 3.17.0)
|
74
74
|
parallel (~> 1.10)
|
@@ -120,4 +120,4 @@ DEPENDENCIES
|
|
120
120
|
sqlite3 (< 2)
|
121
121
|
|
122
122
|
BUNDLED WITH
|
123
|
-
2.
|
123
|
+
2.5.9
|
data/README.md
CHANGED
@@ -8,7 +8,8 @@ Enumerations for Ruby with some magic powers! 🎩
|
|
8
8
|
[![Downloads](https://img.shields.io/gem/dt/enumerate_it.svg)](https://rubygems.org/gems/enumerate_it)
|
9
9
|
[![Changelog](https://img.shields.io/badge/changelog--brightgreen.svg?style=flat)](https://github.com/lucascaton/enumerate_it/releases)
|
10
10
|
|
11
|
-
**EnumerateIt** helps you to declare and use enumerations in a very simple and
|
11
|
+
**EnumerateIt** helps you to declare and use enumerations in a very simple and
|
12
|
+
flexible way.
|
12
13
|
|
13
14
|
### Why would I want a gem if Rails already has native enumerations support?
|
14
15
|
|
@@ -21,16 +22,27 @@ so you can **add behaviour** and also **reuse** them! 😀
|
|
21
22
|
|
22
23
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
- [
|
27
|
-
- [
|
28
|
-
- [
|
29
|
-
- [
|
30
|
-
- [
|
31
|
-
- [
|
32
|
-
- [
|
33
|
-
- [
|
25
|
+
## Table of Contents
|
26
|
+
|
27
|
+
- [EnumerateIt](#enumerateit)
|
28
|
+
- [Why would I want a gem if Rails already has native enumerations support?](#why-would-i-want-a-gem-if-rails-already-has-native-enumerations-support)
|
29
|
+
- [Table of Contents](#table-of-contents)
|
30
|
+
- [Installation](#installation)
|
31
|
+
- [Using with Rails](#using-with-rails)
|
32
|
+
- [Creating enumerations](#creating-enumerations)
|
33
|
+
- [Sorting enumerations](#sorting-enumerations)
|
34
|
+
- [Using enumerations](#using-enumerations)
|
35
|
+
- [FAQ](#faq)
|
36
|
+
- [Why define enumerations outside the class that uses them?](#why-define-enumerations-outside-the-class-that-uses-them)
|
37
|
+
- [Can I use `enumerate_it` gem without Rails?](#can-i-use-enumerate_it-gem-without-rails)
|
38
|
+
- [What versions of Ruby and Rails are supported?](#what-versions-of-ruby-and-rails-are-supported)
|
39
|
+
- [Can I set a value to always be at the end of a sorted list?](#can-i-set-a-value-to-always-be-at-the-end-of-a-sorted-list)
|
40
|
+
- [I18n](#i18n)
|
41
|
+
- [Translate a name-spaced enumeration](#translate-a-name-spaced-enumeration)
|
42
|
+
- [Handling a legacy database](#handling-a-legacy-database)
|
43
|
+
- [Changelog](#changelog)
|
44
|
+
- [Note on Patches/Pull Requests](#note-on-patchespull-requests)
|
45
|
+
- [Copyright](#copyright)
|
34
46
|
|
35
47
|
<!-- Tocer[finish]: Auto-generated, don't remove. -->
|
36
48
|
|
@@ -56,10 +68,11 @@ rails generate enumerate_it:enum --help
|
|
56
68
|
|
57
69
|
## Creating enumerations
|
58
70
|
|
59
|
-
Enumerations are created as classes and you should put them inside
|
71
|
+
Enumerations are created as classes and you should put them inside
|
72
|
+
`app/enumerations` folder.
|
60
73
|
|
61
|
-
You can pass an array of symbols, so that the respective value for each symbol
|
62
|
-
stringified version of the symbol itself:
|
74
|
+
You can pass an array of symbols, so that the respective value for each symbol
|
75
|
+
will be the stringified version of the symbol itself:
|
63
76
|
|
64
77
|
```ruby
|
65
78
|
class RelationshipStatus < EnumerateIt::Base
|
@@ -73,7 +86,7 @@ end
|
|
73
86
|
|
74
87
|
This will create some nice stuff:
|
75
88
|
|
76
|
-
|
89
|
+
- Each enumeration's value will turn into a constant:
|
77
90
|
|
78
91
|
```ruby
|
79
92
|
RelationshipStatus::SINGLE
|
@@ -83,68 +96,68 @@ This will create some nice stuff:
|
|
83
96
|
#=> 'married'
|
84
97
|
```
|
85
98
|
|
86
|
-
|
99
|
+
- You can retrieve a list with all the enumeration codes:
|
87
100
|
|
88
101
|
```ruby
|
89
102
|
RelationshipStatus.list
|
90
103
|
#=> ['divorced', 'married', 'single']
|
91
104
|
```
|
92
105
|
|
93
|
-
|
106
|
+
- You can retrieve a JSON with all the enumeration codes:
|
94
107
|
|
95
108
|
```ruby
|
96
109
|
RelationshipStatus.to_json
|
97
110
|
#=> "[{\"value\":\"divorced\",\"label\":\"Divorced\"},{\"value\":\"married\", ...
|
98
111
|
```
|
99
112
|
|
100
|
-
|
101
|
-
Rails helpers.
|
113
|
+
- You can get an array of options, ready to use with the `select`, `select_tag`,
|
114
|
+
etc. family of Rails helpers.
|
102
115
|
|
103
116
|
```ruby
|
104
117
|
RelationshipStatus.to_a
|
105
118
|
#=> [['Divorced', 'divorced'], ['Married', 'married'], ['Single', 'single']]
|
106
119
|
```
|
107
120
|
|
108
|
-
|
121
|
+
- You can retrieve a list with values for a group of enumeration constants.
|
109
122
|
|
110
123
|
```ruby
|
111
124
|
RelationshipStatus.values_for %w(MARRIED SINGLE)
|
112
125
|
#=> ['married', 'single']
|
113
126
|
```
|
114
127
|
|
115
|
-
|
128
|
+
- You can retrieve the value for a specific enumeration constant:
|
116
129
|
|
117
130
|
```ruby
|
118
131
|
RelationshipStatus.value_for('MARRIED')
|
119
132
|
#=> 'married'
|
120
133
|
```
|
121
134
|
|
122
|
-
|
135
|
+
- You can retrieve the symbol used to declare a specific enumeration value:
|
123
136
|
|
124
137
|
```ruby
|
125
138
|
RelationshipStatus.key_for(RelationshipStatus::MARRIED)
|
126
139
|
#=> :married
|
127
140
|
```
|
128
141
|
|
129
|
-
|
142
|
+
- You can iterate over the list of the enumeration's values:
|
130
143
|
|
131
144
|
```ruby
|
132
145
|
RelationshipStatus.each_value { |value| ... }
|
133
146
|
```
|
134
147
|
|
135
|
-
|
148
|
+
- You can iterate over the list of the enumeration's translations:
|
136
149
|
|
137
150
|
```ruby
|
138
151
|
RelationshipStatus.each_translation { |translation| ... }
|
139
152
|
```
|
140
153
|
|
141
|
-
|
154
|
+
- You can also retrieve all the translations of the enumeration:
|
142
155
|
|
143
156
|
```ruby
|
144
157
|
RelationshipStatus.translations
|
145
158
|
```
|
146
159
|
|
147
|
-
|
160
|
+
- You can ask for the enumeration's length:
|
148
161
|
|
149
162
|
```ruby
|
150
163
|
RelationshipStatus.length
|
@@ -153,11 +166,11 @@ This will create some nice stuff:
|
|
153
166
|
|
154
167
|
### Sorting enumerations
|
155
168
|
|
156
|
-
When calling methods like `to_a`, `to_json` and `list`, the returned values will
|
157
|
-
default in the same order passed to `associate_values` call.
|
158
|
-
|
159
|
-
However, if you want to overwrite the default sort mode, you can use the `sort_by` class method:
|
169
|
+
When calling methods like `to_a`, `to_json` and `list`, the returned values will
|
170
|
+
be sorted by default in the same order passed to `associate_values` call.
|
160
171
|
|
172
|
+
However, if you want to overwrite the default sort mode, you can use the
|
173
|
+
`sort_by` class method:
|
161
174
|
|
162
175
|
```ruby
|
163
176
|
class RelationshipStatus < EnumerateIt::Base
|
@@ -197,14 +210,15 @@ class Person
|
|
197
210
|
end
|
198
211
|
```
|
199
212
|
|
200
|
-
> **Note:** **EnumerateIt** will try to load an enumeration class based on the
|
201
|
-
> name. If you have a different name, you can specify it by
|
213
|
+
> **Note:** **EnumerateIt** will try to load an enumeration class based on the
|
214
|
+
> camelized attribute name. If you have a different name, you can specify it by
|
215
|
+
> using the `with` option:
|
202
216
|
>
|
203
217
|
> `has_enumeration_for :relationship_status, with: RelationshipStatus`
|
204
218
|
|
205
219
|
This will create:
|
206
220
|
|
207
|
-
|
221
|
+
- A "humanized" version of the hash's key to humanize the attribute's value:
|
208
222
|
|
209
223
|
```ruby
|
210
224
|
p = Person.new
|
@@ -213,8 +227,8 @@ This will create:
|
|
213
227
|
#=> 'Divorced'
|
214
228
|
```
|
215
229
|
|
216
|
-
|
217
|
-
|
230
|
+
- A translation for your options, if you include a locale to represent it (see
|
231
|
+
more in the [I18n section](#i18n)).
|
218
232
|
|
219
233
|
```ruby
|
220
234
|
p = Person.new
|
@@ -223,14 +237,16 @@ This will create:
|
|
223
237
|
#=> 'Divorciado'
|
224
238
|
```
|
225
239
|
|
226
|
-
|
240
|
+
- The associated enumerations, which can be retrieved with the `enumerations`
|
241
|
+
class method:
|
227
242
|
|
228
243
|
```ruby
|
229
244
|
Person.enumerations
|
230
245
|
#=> { relationship_status: RelationshipStatus }
|
231
246
|
```
|
232
247
|
|
233
|
-
|
248
|
+
- A helper method for each enumeration option, if you pass the `create_helpers`
|
249
|
+
option as `true`:
|
234
250
|
|
235
251
|
```ruby
|
236
252
|
class Person < ApplicationRecord
|
@@ -247,8 +263,9 @@ This will create:
|
|
247
263
|
#=> false
|
248
264
|
```
|
249
265
|
|
250
|
-
It's also possible to "namespace" the created helper methods, passing a hash
|
251
|
-
option. This can be useful when two or more of the
|
266
|
+
It's also possible to "namespace" the created helper methods, passing a hash
|
267
|
+
to the `create_helpers` option. This can be useful when two or more of the
|
268
|
+
enumerations used share the same constants:
|
252
269
|
|
253
270
|
```ruby
|
254
271
|
class Person < ApplicationRecord
|
@@ -266,8 +283,8 @@ This will create:
|
|
266
283
|
#=> false
|
267
284
|
```
|
268
285
|
|
269
|
-
You can define polymorphic behavior for the enumeration values, so you can
|
270
|
-
of them:
|
286
|
+
You can define polymorphic behavior for the enumeration values, so you can
|
287
|
+
define a class for each of them:
|
271
288
|
|
272
289
|
```ruby
|
273
290
|
class RelationshipStatus < EnumerateIt::Base
|
@@ -312,8 +329,8 @@ This will create:
|
|
312
329
|
p.relationship_status_mode.saturday_night
|
313
330
|
```
|
314
331
|
|
315
|
-
The `create_helpers` also creates some mutator helper methods, that can be
|
316
|
-
attribute's value.
|
332
|
+
The `create_helpers` also creates some mutator helper methods, that can be
|
333
|
+
used to change the attribute's value.
|
317
334
|
|
318
335
|
```ruby
|
319
336
|
p = Person.new
|
@@ -323,7 +340,8 @@ This will create:
|
|
323
340
|
#=> true
|
324
341
|
```
|
325
342
|
|
326
|
-
|
343
|
+
- A scope method for each enumeration option if you pass the `create_scopes`
|
344
|
+
option as `true`:
|
327
345
|
|
328
346
|
```ruby
|
329
347
|
class Person < ApplicationRecord
|
@@ -345,7 +363,7 @@ This will create:
|
|
345
363
|
Person.relationship_status_married.to_sql
|
346
364
|
```
|
347
365
|
|
348
|
-
|
366
|
+
- An inclusion validation (if your class can manage validations and responds to
|
349
367
|
`validates_inclusion_of`):
|
350
368
|
|
351
369
|
```ruby
|
@@ -360,7 +378,7 @@ This will create:
|
|
360
378
|
#=> 'is not included in the list'
|
361
379
|
```
|
362
380
|
|
363
|
-
|
381
|
+
- A presence validation (if your class can manage validations and responds to
|
364
382
|
`validates_presence_of` and you pass the `required` options as `true`):
|
365
383
|
|
366
384
|
```ruby
|
@@ -375,7 +393,8 @@ This will create:
|
|
375
393
|
#=> "can't be blank"
|
376
394
|
```
|
377
395
|
|
378
|
-
If you pass the `skip_validation` option as `true`, it will not create any
|
396
|
+
If you pass the `skip_validation` option as `true`, it will not create any
|
397
|
+
validations:
|
379
398
|
|
380
399
|
```ruby
|
381
400
|
class Person < ApplicationRecord
|
@@ -387,15 +406,16 @@ This will create:
|
|
387
406
|
#=> true
|
388
407
|
```
|
389
408
|
|
390
|
-
Remember that you can add validations to any kind of class and not only
|
409
|
+
Remember that you can add validations to any kind of class and not only
|
410
|
+
`ActiveRecord` ones.
|
391
411
|
|
392
412
|
## FAQ
|
393
413
|
|
394
414
|
#### Why define enumerations outside the class that uses them?
|
395
415
|
|
396
|
-
|
397
|
-
|
398
|
-
|
416
|
+
- It's clearer.
|
417
|
+
- You can add behaviour to the enumeration class.
|
418
|
+
- You can reuse the enumeration inside other classes.
|
399
419
|
|
400
420
|
#### Can I use `enumerate_it` gem without Rails?
|
401
421
|
|
@@ -403,20 +423,22 @@ You sure can! 😄
|
|
403
423
|
|
404
424
|
#### What versions of Ruby and Rails are supported?
|
405
425
|
|
406
|
-
|
407
|
-
|
426
|
+
- **Ruby**: `3.0+`
|
427
|
+
- **Rails** `6.0+`
|
408
428
|
|
409
429
|
All versions are tested via
|
410
430
|
[GitHub Actions](https://github.com/lucascaton/enumerate_it/blob/HEAD/.github/workflows/ci.yml).
|
411
431
|
|
412
432
|
#### Can I set a value to always be at the end of a sorted list?
|
413
433
|
|
414
|
-
Yes,
|
434
|
+
Yes,
|
435
|
+
[see more details here](https://github.com/lucascaton/enumerate_it/issues/60).
|
415
436
|
|
416
437
|
## I18n
|
417
438
|
|
418
|
-
I18n lookup is provided on both `_humanized` and `Enumeration#to_a` methods,
|
419
|
-
a Symbol. The I18n strings are located on
|
439
|
+
I18n lookup is provided on both `_humanized` and `Enumeration#to_a` methods,
|
440
|
+
given the hash key is a Symbol. The I18n strings are located on
|
441
|
+
`enumerations.<enumeration_name>.<key>`:
|
420
442
|
|
421
443
|
```yaml
|
422
444
|
# Your locale file
|
@@ -454,22 +476,22 @@ RelationshipStatus.t(status)
|
|
454
476
|
|
455
477
|
### Translate a name-spaced enumeration
|
456
478
|
|
457
|
-
In order to translate an enumeration in a specific namespace (say
|
458
|
-
you can add the following:
|
479
|
+
In order to translate an enumeration in a specific namespace (say
|
480
|
+
`Design::Color`), you can add the following:
|
459
481
|
|
460
482
|
```yaml
|
461
483
|
pt-BR:
|
462
484
|
enumerations:
|
463
|
-
|
485
|
+
"design/color":
|
464
486
|
blue: Azul
|
465
487
|
red: Vermelho
|
466
488
|
```
|
467
489
|
|
468
490
|
## Handling a legacy database
|
469
491
|
|
470
|
-
**EnumerateIt** can help you build a Rails application around a legacy database
|
471
|
-
with those small and unchangeable tables used to create foreign
|
472
|
-
following example:
|
492
|
+
**EnumerateIt** can help you build a Rails application around a legacy database
|
493
|
+
which was filled with those small and unchangeable tables used to create foreign
|
494
|
+
key constraints everywhere, like the following example:
|
473
495
|
|
474
496
|
```sql
|
475
497
|
Table "public.relationship_status"
|
@@ -491,14 +513,16 @@ code | description
|
|
491
513
|
3 | Divorced
|
492
514
|
```
|
493
515
|
|
494
|
-
You might also have something like a `users` table with a `relationship_status`
|
495
|
-
key pointing to the `relationship_status` table.
|
516
|
+
You might also have something like a `users` table with a `relationship_status`
|
517
|
+
column and a foreign key pointing to the `relationship_status` table.
|
496
518
|
|
497
|
-
While this is a good thing from the database normalization perspective, managing
|
498
|
-
tests is very hard. Doing database joins just to get the
|
499
|
-
And, more than this, referencing them in
|
500
|
-
|
501
|
-
|
519
|
+
While this is a good thing from the database normalization perspective, managing
|
520
|
+
these values in tests is very hard. Doing database joins just to get the
|
521
|
+
description of some value is absurd. And, more than this, referencing them in
|
522
|
+
the code using
|
523
|
+
[magic numbers](<https://en.wikipedia.org/wiki/Magic_number_(programming)>) was
|
524
|
+
terrible and meaningless: what does it mean when we say that someone or
|
525
|
+
something is `2`?
|
502
526
|
|
503
527
|
To solve this, you can pass a **hash** to your enumeration values:
|
504
528
|
|
@@ -526,14 +550,18 @@ you can see them on the [releases page](../../releases).
|
|
526
550
|
|
527
551
|
## Note on Patches/Pull Requests
|
528
552
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
553
|
+
- Fork the project.
|
554
|
+
- Make your feature addition or bug fix.
|
555
|
+
- Add tests for it. This is important so we don't break it in a future version
|
556
|
+
unintentionally.
|
557
|
+
- [Optional] Run the tests against a specific Gemfile:
|
558
|
+
`$ bundle exec appraisal rails_7.0 rake spec`.
|
559
|
+
- Run the tests against all supported versions: `$ bundle exec rake` (or
|
560
|
+
`$ bundle exec wwtd`)
|
561
|
+
- Commit, but please do not mess with `Rakefile`, version, or history.
|
562
|
+
- Send a Pull Request. Bonus points for topic branches.
|
536
563
|
|
537
564
|
## Copyright
|
538
565
|
|
539
|
-
Copyright (c) 2010-2024 Cássio Marques and Lucas Caton. See `LICENSE` file for
|
566
|
+
Copyright (c) 2010-2024 Cássio Marques and Lucas Caton. See `LICENSE` file for
|
567
|
+
details.
|
data/enumerate_it.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.name = 'enumerate_it'
|
13
13
|
gem.require_paths = ['lib']
|
14
14
|
gem.version = EnumerateIt::VERSION
|
15
|
-
gem.required_ruby_version = '>=
|
15
|
+
gem.required_ruby_version = '>= 3.0.0'
|
16
16
|
|
17
17
|
gem.metadata = {
|
18
18
|
'source_code_uri' => 'https://github.com/lucascaton/enumerate_it',
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |gem|
|
|
20
20
|
'rubygems_mfa_required' => 'true'
|
21
21
|
}
|
22
22
|
|
23
|
-
gem.add_dependency 'activesupport', '>=
|
23
|
+
gem.add_dependency 'activesupport', '>= 6.0.0'
|
24
24
|
|
25
25
|
gem.add_development_dependency 'activerecord'
|
26
26
|
gem.add_development_dependency 'appraisal'
|
data/lib/enumerate_it/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -5,7 +5,7 @@ require 'enumerate_it'
|
|
5
5
|
require 'active_support/all'
|
6
6
|
require 'active_record'
|
7
7
|
|
8
|
-
Dir['./spec/support/**/*.rb'].
|
8
|
+
Dir['./spec/support/**/*.rb'].each { |f| require f }
|
9
9
|
|
10
10
|
I18n.config.enforce_available_locales = false
|
11
11
|
I18n.load_path = Dir['spec/i18n/*.yml']
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: enumerate_it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 4.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cássio Marques
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-04-
|
12
|
+
date: 2024-04-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -17,14 +17,14 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version:
|
20
|
+
version: 6.0.0
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version:
|
27
|
+
version: 6.0.0
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: activerecord
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -184,9 +184,6 @@ files:
|
|
184
184
|
- README.md
|
185
185
|
- Rakefile
|
186
186
|
- enumerate_it.gemspec
|
187
|
-
- gemfiles/rails_5.0.gemfile
|
188
|
-
- gemfiles/rails_5.1.gemfile
|
189
|
-
- gemfiles/rails_5.2.gemfile
|
190
187
|
- gemfiles/rails_6.0.gemfile
|
191
188
|
- gemfiles/rails_6.1.gemfile
|
192
189
|
- gemfiles/rails_7.0.gemfile
|
@@ -220,14 +217,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
220
217
|
requirements:
|
221
218
|
- - ">="
|
222
219
|
- !ruby/object:Gem::Version
|
223
|
-
version:
|
220
|
+
version: 3.0.0
|
224
221
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
222
|
requirements:
|
226
223
|
- - ">="
|
227
224
|
- !ruby/object:Gem::Version
|
228
225
|
version: '0'
|
229
226
|
requirements: []
|
230
|
-
rubygems_version: 3.5.
|
227
|
+
rubygems_version: 3.5.9
|
231
228
|
signing_key:
|
232
229
|
specification_version: 4
|
233
230
|
summary: Ruby Enumerations
|
data/gemfiles/rails_5.0.gemfile
DELETED
data/gemfiles/rails_5.1.gemfile
DELETED