enumerate_it 4.0.0 → 4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 57b418cb6e9cf24f8b935c898004ddc62ba373f9c03b4c3df600339a26e7d16e
4
- data.tar.gz: 4625233483bf656e0e75d9d116dff98fb1801f31e348c54e643bd501081da1fd
3
+ metadata.gz: 0e0e2aa1d31c14c5e310f50feb06824c19e7bffa49d08ab1f29d8f3a9b45e32d
4
+ data.tar.gz: a6e1642362885b5e306c713dd54c859452c2392bb17c012e039c84bd8878f9e9
5
5
  SHA512:
6
- metadata.gz: af19adb823775b00e138df51023b4a724219e9c12958218fb63cbea843fecb0ce8a97657a3ec6aceca2d2db4818b9415c6a94f5105bb31dbca415b542acf3158
7
- data.tar.gz: bbaab168f1ba3c5199eced5b46244dae3499b459a8941d9719a3f264cc5a08d46c2d5356aae9381a686c46bce0cc43df6a4230ae2e4fe8266f4bb5a8335ae708
6
+ metadata.gz: ea12eb1fe75185a0525f0580906391e37d5b540bcc09f273a2cac96c7e168994b184f549c54cd04af9940452355fd159d449c199db5855cdf0b0b03c209dd8f6
7
+ data.tar.gz: f2793a073ffb559e162970e069bc5136d08b03e74dd77f885c1f27d041c48c7d25fb83de9c982bcfb4e1105149635272db5ef8ee4d86c228666c87318baae765
@@ -13,11 +13,20 @@ jobs:
13
13
  - 3.1
14
14
  - 3.2
15
15
  - 3.3
16
+ - 3.4
16
17
  gemfile:
17
18
  - gemfiles/rails_6.0.gemfile
18
19
  - gemfiles/rails_6.1.gemfile
19
20
  - gemfiles/rails_7.0.gemfile
20
21
  - gemfiles/rails_7.1.gemfile
22
+ - gemfiles/rails_7.2.gemfile
23
+ - gemfiles/rails_8.0.gemfile
24
+ exclude:
25
+ # Rails 8 requires Ruby 3.2 or newer
26
+ - ruby: 3.0
27
+ gemfile: gemfiles/rails_8.0.gemfile
28
+ - ruby: 3.1
29
+ gemfile: gemfiles/rails_8.0.gemfile
21
30
 
22
31
  env:
23
32
  BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
@@ -34,7 +43,7 @@ jobs:
34
43
  bundler-cache: true
35
44
 
36
45
  - name: Rubocop
37
- if: ${{ matrix.ruby == '3.3' }}
46
+ if: ${{ matrix.ruby == '3.4' }}
38
47
  run: "bundle exec rubocop"
39
48
 
40
49
  - name: Tests
data/.rubocop.yml CHANGED
@@ -1,4 +1,4 @@
1
- require:
1
+ plugins:
2
2
  - rubocop-rspec
3
3
  - rubocop-rake
4
4
 
@@ -8,7 +8,7 @@ inherit_mode:
8
8
 
9
9
  AllCops:
10
10
  NewCops: enable
11
- TargetRubyVersion: 3.0
11
+ TargetRubyVersion: 3.4
12
12
 
13
13
  Exclude:
14
14
  - 'lib/generators/enumerate_it/enum/templates/**/*'
data/Appraisals CHANGED
@@ -2,9 +2,9 @@ require 'net/http'
2
2
  require 'json'
3
3
 
4
4
  rails_versions = JSON.parse(Net::HTTP.get(URI('https://rubygems.org/api/v1/versions/rails.json')))
5
- .group_by { |version| version['number'] }.keys.grep_v(/rc|racecar|beta|pre/)
5
+ .group_by { |version| version['number'] }.keys.grep_v(/rc|racecar|alpha|beta|pre/)
6
6
 
7
- %w[6.0 6.1 7.0 7.1].each do |rails_version|
7
+ %w[6.0 6.1 7.0 7.1 7.2 8.0].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,6 +13,18 @@ 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
- gem 'sqlite3', '< 2' # v2.x isn't yet working. See: https://github.com/sparklemotion/sqlite3-ruby/issues/529
16
+ if Gem::Version.new(rails_version) > Gem::Version.new(7.0)
17
+ gem 'sqlite3'
18
+ else
19
+ gem 'sqlite3', '< 2' # Rails 6.x and 7.0 require sqlite3 v1.x
20
+ end
21
+
22
+ # The following is likely necessary due to this issue (or something related):
23
+ # https://stackoverflow.com/a/79385484/1445184
24
+ if Gem::Version.new(rails_version) < Gem::Version.new(7.1)
25
+ gem 'base64'
26
+ gem 'bigdecimal'
27
+ gem 'mutex_m'
28
+ end
17
29
  end
18
30
  end
data/Gemfile.lock CHANGED
@@ -1,107 +1,110 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumerate_it (4.0.0)
4
+ enumerate_it (4.1.0)
5
5
  activesupport (>= 6.0.0)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activemodel (7.1.3.2)
11
- activesupport (= 7.1.3.2)
12
- activerecord (7.1.3.2)
13
- activemodel (= 7.1.3.2)
14
- activesupport (= 7.1.3.2)
10
+ activemodel (8.0.2)
11
+ activesupport (= 8.0.2)
12
+ activerecord (8.0.2)
13
+ activemodel (= 8.0.2)
14
+ activesupport (= 8.0.2)
15
15
  timeout (>= 0.4.0)
16
- activesupport (7.1.3.2)
16
+ activesupport (8.0.2)
17
17
  base64
18
+ benchmark (>= 0.3)
18
19
  bigdecimal
19
- concurrent-ruby (~> 1.0, >= 1.0.2)
20
+ concurrent-ruby (~> 1.0, >= 1.3.1)
20
21
  connection_pool (>= 2.2.5)
21
22
  drb
22
23
  i18n (>= 1.6, < 2)
24
+ logger (>= 1.4.2)
23
25
  minitest (>= 5.1)
24
- mutex_m
25
- tzinfo (~> 2.0)
26
+ securerandom (>= 0.3)
27
+ tzinfo (~> 2.0, >= 2.0.5)
28
+ uri (>= 0.13.1)
26
29
  appraisal (2.5.0)
27
30
  bundler
28
31
  rake
29
32
  thor (>= 0.14.0)
30
- ast (2.4.2)
33
+ ast (2.4.3)
31
34
  base64 (0.2.0)
32
- bigdecimal (3.1.7)
35
+ benchmark (0.4.0)
36
+ bigdecimal (3.1.9)
33
37
  coderay (1.1.3)
34
- concurrent-ruby (1.2.3)
35
- connection_pool (2.4.1)
36
- diff-lcs (1.5.1)
38
+ concurrent-ruby (1.3.5)
39
+ connection_pool (2.5.3)
40
+ diff-lcs (1.6.1)
37
41
  drb (2.2.1)
38
- i18n (1.14.4)
42
+ i18n (1.14.7)
39
43
  concurrent-ruby (~> 1.0)
40
- json (2.7.2)
41
- language_server-protocol (3.17.0.3)
44
+ json (2.11.3)
45
+ language_server-protocol (3.17.0.4)
46
+ lint_roller (1.1.0)
47
+ logger (1.7.0)
42
48
  method_source (1.1.0)
43
- mini_portile2 (2.8.6)
44
- minitest (5.22.3)
45
- mutex_m (0.2.0)
46
- parallel (1.24.0)
47
- parser (3.3.1.0)
49
+ mini_portile2 (2.8.8)
50
+ minitest (5.25.5)
51
+ parallel (1.27.0)
52
+ parser (3.3.8.0)
48
53
  ast (~> 2.4.1)
49
54
  racc
50
- pry (0.14.2)
55
+ prism (1.4.0)
56
+ pry (0.15.2)
51
57
  coderay (~> 1.1)
52
58
  method_source (~> 1.0)
53
- racc (1.7.3)
59
+ racc (1.8.1)
54
60
  rainbow (3.1.1)
55
61
  rake (13.2.1)
56
- regexp_parser (2.9.0)
57
- rexml (3.2.6)
62
+ regexp_parser (2.10.0)
58
63
  rspec (3.13.0)
59
64
  rspec-core (~> 3.13.0)
60
65
  rspec-expectations (~> 3.13.0)
61
66
  rspec-mocks (~> 3.13.0)
62
- rspec-core (3.13.0)
67
+ rspec-core (3.13.3)
63
68
  rspec-support (~> 3.13.0)
64
- rspec-expectations (3.13.0)
69
+ rspec-expectations (3.13.3)
65
70
  diff-lcs (>= 1.2.0, < 2.0)
66
71
  rspec-support (~> 3.13.0)
67
- rspec-mocks (3.13.0)
72
+ rspec-mocks (3.13.2)
68
73
  diff-lcs (>= 1.2.0, < 2.0)
69
74
  rspec-support (~> 3.13.0)
70
- rspec-support (3.13.1)
71
- rubocop (1.63.3)
75
+ rspec-support (3.13.2)
76
+ rubocop (1.75.4)
72
77
  json (~> 2.3)
73
- language_server-protocol (>= 3.17.0)
78
+ language_server-protocol (~> 3.17.0.2)
79
+ lint_roller (~> 1.1.0)
74
80
  parallel (~> 1.10)
75
81
  parser (>= 3.3.0.2)
76
82
  rainbow (>= 2.2.2, < 4.0)
77
- regexp_parser (>= 1.8, < 3.0)
78
- rexml (>= 3.2.5, < 4.0)
79
- rubocop-ast (>= 1.31.1, < 2.0)
83
+ regexp_parser (>= 2.9.3, < 3.0)
84
+ rubocop-ast (>= 1.44.0, < 2.0)
80
85
  ruby-progressbar (~> 1.7)
81
- unicode-display_width (>= 2.4.0, < 3.0)
82
- rubocop-ast (1.31.2)
83
- parser (>= 3.3.0.4)
84
- rubocop-capybara (2.20.0)
85
- rubocop (~> 1.41)
86
- rubocop-factory_bot (2.25.1)
87
- rubocop (~> 1.41)
88
- rubocop-rake (0.6.0)
89
- rubocop (~> 1.0)
90
- rubocop-rspec (2.29.1)
91
- rubocop (~> 1.40)
92
- rubocop-capybara (~> 2.17)
93
- rubocop-factory_bot (~> 2.22)
94
- rubocop-rspec_rails (~> 2.28)
95
- rubocop-rspec_rails (2.28.3)
96
- rubocop (~> 1.40)
86
+ unicode-display_width (>= 2.4.0, < 4.0)
87
+ rubocop-ast (1.44.1)
88
+ parser (>= 3.3.7.2)
89
+ prism (~> 1.4)
90
+ rubocop-rake (0.7.1)
91
+ lint_roller (~> 1.1)
92
+ rubocop (>= 1.72.1)
93
+ rubocop-rspec (3.6.0)
94
+ lint_roller (~> 1.1)
95
+ rubocop (~> 1.72, >= 1.72.1)
97
96
  ruby-progressbar (1.13.0)
97
+ securerandom (0.4.1)
98
98
  sqlite3 (1.7.3)
99
99
  mini_portile2 (~> 2.8.0)
100
- thor (1.3.1)
101
- timeout (0.4.1)
100
+ thor (1.3.2)
101
+ timeout (0.4.3)
102
102
  tzinfo (2.0.6)
103
103
  concurrent-ruby (~> 1.0)
104
- unicode-display_width (2.5.0)
104
+ unicode-display_width (3.1.4)
105
+ unicode-emoji (~> 4.0, >= 4.0.4)
106
+ unicode-emoji (4.0.4)
107
+ uri (1.0.3)
105
108
 
106
109
  PLATFORMS
107
110
  ruby
@@ -120,4 +123,4 @@ DEPENDENCIES
120
123
  sqlite3 (< 2)
121
124
 
122
125
  BUNDLED WITH
123
- 2.5.9
126
+ 2.6.6
data/LICENSE CHANGED
@@ -2,7 +2,7 @@ LICENSE
2
2
 
3
3
  The MIT License
4
4
 
5
- Copyright (c) 2010-2020 Cássio Marques and Lucas Caton
5
+ Copyright (c) 2010-2025 Cássio Marques and Lucas Caton
6
6
 
7
7
  Permission is hereby granted, free of charge, to any person obtaining
8
8
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -4,19 +4,18 @@ Enumerations for Ruby with some magic powers! 🎩
4
4
 
5
5
  [![CI Status](https://github.com/lucascaton/enumerate_it/workflows/CI/badge.svg)](https://github.com/lucascaton/enumerate_it/actions?query=workflow%3ACI)
6
6
  [![Gem Version](https://badge.fury.io/rb/enumerate_it.svg)](https://rubygems.org/gems/enumerate_it)
7
- [![Code Climate](https://codeclimate.com/github/lucascaton/enumerate_it/badges/gpa.svg)](https://codeclimate.com/github/lucascaton/enumerate_it)
8
7
  [![Downloads](https://img.shields.io/gem/dt/enumerate_it.svg)](https://rubygems.org/gems/enumerate_it)
9
8
  [![Changelog](https://img.shields.io/badge/changelog--brightgreen.svg?style=flat)](https://github.com/lucascaton/enumerate_it/releases)
10
9
 
11
- **EnumerateIt** helps you to declare and use enumerations in a very simple and
10
+ **EnumerateIt** helps you declare and use enumerations in a very simple and
12
11
  flexible way.
13
12
 
14
- ### Why would I want a gem if Rails already has native enumerations support?
13
+ ### Why would I want a gem if Rails already has native enumeration support?
15
14
 
16
15
  Firstly, although **EnumerateIt** works well with **Rails**, it isn't required!
17
- It means you can add it to any **Ruby** project! Secondly, you can
18
- [define your enumerations in classes](https://github.com/lucascaton/enumerate_it#creating-enumerations),
19
- so you can **add behaviour** and also **reuse** them! 😀
16
+ This means you can add it to any **Ruby** project! Secondly, you can
17
+ [define your enumerations in classes](#creating-enumerations), allowing you to
18
+ **add behavior** and **reuse** them! 😀
20
19
 
21
20
  ---
22
21
 
@@ -24,21 +23,18 @@ so you can **add behaviour** and also **reuse** them! 😀
24
23
 
25
24
  ## Table of Contents
26
25
 
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
26
  - [Installation](#installation)
31
27
  - [Using with Rails](#using-with-rails)
32
28
  - [Creating enumerations](#creating-enumerations)
33
29
  - [Sorting enumerations](#sorting-enumerations)
34
30
  - [Using enumerations](#using-enumerations)
35
31
  - [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)
32
+ - [Why define enumerations outside the class that uses them?](#why-define-enumerations-outside-the-class-that-uses-them)
33
+ - [Can I use `enumerate_it` gem without Rails?](#can-i-use-enumerate_it-gem-without-rails)
34
+ - [What versions of Ruby and Rails are supported?](#what-versions-of-ruby-and-rails-are-supported)
35
+ - [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
36
  - [I18n](#i18n)
41
- - [Translate a name-spaced enumeration](#translate-a-name-spaced-enumeration)
37
+ - [Translate a namespaced enumeration](#translate-a-namespaced-enumeration)
42
38
  - [Handling a legacy database](#handling-a-legacy-database)
43
39
  - [Changelog](#changelog)
44
40
  - [Note on Patches/Pull Requests](#note-on-patchespull-requests)
@@ -68,11 +64,11 @@ rails generate enumerate_it:enum --help
68
64
 
69
65
  ## Creating enumerations
70
66
 
71
- Enumerations are created as classes and you should put them inside
67
+ Enumerations are created as classes and should be placed inside the
72
68
  `app/enumerations` folder.
73
69
 
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:
70
+ You can pass an array of symbols, where each symbol's value will be its
71
+ stringified version:
76
72
 
77
73
  ```ruby
78
74
  class RelationshipStatus < EnumerateIt::Base
@@ -84,9 +80,9 @@ class RelationshipStatus < EnumerateIt::Base
84
80
  end
85
81
  ```
86
82
 
87
- This will create some nice stuff:
83
+ This will generate some nice stuff:
88
84
 
89
- - Each enumeration's value will turn into a constant:
85
+ - Constants for each enumeration value:
90
86
 
91
87
  ```ruby
92
88
  RelationshipStatus::SINGLE
@@ -96,22 +92,21 @@ This will create some nice stuff:
96
92
  #=> 'married'
97
93
  ```
98
94
 
99
- - You can retrieve a list with all the enumeration codes:
95
+ - A list of all enumeration codes:
100
96
 
101
97
  ```ruby
102
98
  RelationshipStatus.list
103
99
  #=> ['divorced', 'married', 'single']
104
100
  ```
105
101
 
106
- - You can retrieve a JSON with all the enumeration codes:
102
+ - A JSON representation:
107
103
 
108
104
  ```ruby
109
105
  RelationshipStatus.to_json
110
106
  #=> "[{\"value\":\"divorced\",\"label\":\"Divorced\"},{\"value\":\"married\", ...
111
107
  ```
112
108
 
113
- - You can get an array of options, ready to use with the `select`, `select_tag`,
114
- etc. family of Rails helpers.
109
+ - An array of options for Rails helpers, such as `select`, `select_tag`, etc.:
115
110
 
116
111
  ```ruby
117
112
  RelationshipStatus.to_a
@@ -166,11 +161,10 @@ This will create some nice stuff:
166
161
 
167
162
  ### Sorting enumerations
168
163
 
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.
164
+ When calling methods like `to_a`, `to_json` and `list`, values are sorted in the
165
+ order they were passed to `associate_values`, by default.
171
166
 
172
- However, if you want to overwrite the default sort mode, you can use the
173
- `sort_by` class method:
167
+ You can override this with the `sort_by` class method:
174
168
 
175
169
  ```ruby
176
170
  class RelationshipStatus < EnumerateIt::Base
@@ -180,18 +174,20 @@ class RelationshipStatus < EnumerateIt::Base
180
174
  end
181
175
  ```
182
176
 
183
- The `sort_by` method accepts one of the following values:
177
+ Accepted values for `sort_by`:
184
178
 
185
- | Value | Behavior |
186
- | :------------- | :------------------------------------------------------------------------------------------- |
187
- | `:none` | The default behavior, will return values in order that was passed to `associate_values` call |
188
- | `:name` | Will sort the returned values based on the name of each enumeration option |
189
- | `:translation` | will sort the returned values based on their translations |
190
- | `:value` | See [Handling a legacy database](#handling-a-legacy-database) section for more details |
179
+ | Value | Behavior |
180
+ | :----------------------- | :------------------------------------------------------------------------------------ |
181
+ | `:none` | Uses the original order from `associate_values` |
182
+ | `:name` | Sorts by the name of each enumeration option |
183
+ | `:translation` | Sorts by their translations |
184
+ | `:normalize_translation` | Sorts by their translations normalized with NFKD unicode method (without accents) |
185
+ | `:value` | Sorts by assigned values (useful for [legacy databases](#handling-a-legacy-database)) |
191
186
 
192
187
  ## Using enumerations
193
188
 
194
- The cool part is that you can use these enumerations with any class:
189
+ The cool part is that you can use these enumerations in any class, whether
190
+ ActiveRecord-based or not:
195
191
 
196
192
  ```ruby
197
193
  # ActiveRecord instance
@@ -210,9 +206,8 @@ class Person
210
206
  end
211
207
  ```
212
208
 
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:
209
+ > **Note:** If the enumeration class name differs from the attribute name, use
210
+ > the `with` option:
216
211
  >
217
212
  > `has_enumeration_for :relationship_status, with: RelationshipStatus`
218
213
 
@@ -414,7 +409,7 @@ Remember that you can add validations to any kind of class and not only
414
409
  #### Why define enumerations outside the class that uses them?
415
410
 
416
411
  - It's clearer.
417
- - You can add behaviour to the enumeration class.
412
+ - You can add behavior to the enumeration class.
418
413
  - You can reuse the enumeration inside other classes.
419
414
 
420
415
  #### Can I use `enumerate_it` gem without Rails?
@@ -424,7 +419,7 @@ You sure can! 😄
424
419
  #### What versions of Ruby and Rails are supported?
425
420
 
426
421
  - **Ruby**: `3.0+`
427
- - **Rails** `6.0+`
422
+ - **Rails**: `6.0+`
428
423
 
429
424
  All versions are tested via
430
425
  [GitHub Actions](https://github.com/lucascaton/enumerate_it/blob/HEAD/.github/workflows/ci.yml).
@@ -436,7 +431,7 @@ Yes,
436
431
 
437
432
  ## I18n
438
433
 
439
- I18n lookup is provided on both `_humanized` and `Enumeration#to_a` methods,
434
+ I18n lookup is provided for both `_humanized` and `Enumeration#to_a` methods,
440
435
  given the hash key is a Symbol. The I18n strings are located on
441
436
  `enumerations.<enumeration_name>.<key>`:
442
437
 
@@ -474,10 +469,10 @@ RelationshipStatus.t(status)
474
469
  #=> 'Casado'
475
470
  ```
476
471
 
477
- ### Translate a name-spaced enumeration
472
+ ### Translate a namespaced enumeration
478
473
 
479
474
  In order to translate an enumeration in a specific namespace (say
480
- `Design::Color`), you can add the following:
475
+ `Design::Color`), use the following structure:
481
476
 
482
477
  ```yaml
483
478
  pt-BR:
@@ -555,13 +550,12 @@ you can see them on the [releases page](../../releases).
555
550
  - Add tests for it. This is important so we don't break it in a future version
556
551
  unintentionally.
557
552
  - [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`)
553
+ `bundle exec appraisal rails_8.0 rake spec`.
554
+ - Run the tests against all supported versions: `bundle exec rake`
561
555
  - Commit, but please do not mess with `Rakefile`, version, or history.
562
556
  - Send a Pull Request. Bonus points for topic branches.
563
557
 
564
558
  ## Copyright
565
559
 
566
- Copyright (c) 2010-2024 Cássio Marques and Lucas Caton. See `LICENSE` file for
560
+ Copyright (c) 2010-2025 Cássio Marques and Lucas Caton. See `LICENSE` file for
567
561
  details.
@@ -4,6 +4,9 @@ source 'https://rubygems.org'
4
4
 
5
5
  gem 'activerecord', '~> 6.0.6.1'
6
6
  gem 'activesupport', '~> 6.0.6.1'
7
+ gem 'base64'
8
+ gem 'bigdecimal'
9
+ gem 'mutex_m'
7
10
  gem 'sqlite3', '< 2'
8
11
 
9
12
  gemspec path: '../'
@@ -2,8 +2,11 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'activerecord', '~> 6.1.7.7'
6
- gem 'activesupport', '~> 6.1.7.7'
5
+ gem 'activerecord', '~> 6.1.7.10'
6
+ gem 'activesupport', '~> 6.1.7.10'
7
+ gem 'base64'
8
+ gem 'bigdecimal'
9
+ gem 'mutex_m'
7
10
  gem 'sqlite3', '< 2'
8
11
 
9
12
  gemspec path: '../'
@@ -2,8 +2,11 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'activerecord', '~> 7.0.8.1'
6
- gem 'activesupport', '~> 7.0.8.1'
5
+ gem 'activerecord', '~> 7.0.8.7'
6
+ gem 'activesupport', '~> 7.0.8.7'
7
+ gem 'base64'
8
+ gem 'bigdecimal'
9
+ gem 'mutex_m'
7
10
  gem 'sqlite3', '< 2'
8
11
 
9
12
  gemspec path: '../'
@@ -2,8 +2,8 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'activerecord', '~> 7.1.3.2'
6
- gem 'activesupport', '~> 7.1.3.2'
7
- gem 'sqlite3', '< 2'
5
+ gem 'activerecord', '~> 7.1.5.1'
6
+ gem 'activesupport', '~> 7.1.5.1'
7
+ gem 'sqlite3'
8
8
 
9
9
  gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'activerecord', '~> 7.2.2.1'
6
+ gem 'activesupport', '~> 7.2.2.1'
7
+ gem 'sqlite3'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gem 'activerecord', '~> 8.0.2'
6
+ gem 'activesupport', '~> 8.0.2'
7
+ gem 'sqlite3'
8
+
9
+ gemspec path: '../'
@@ -1,7 +1,7 @@
1
1
  require 'forwardable'
2
2
 
3
3
  module EnumerateIt
4
- class Base
4
+ class Base # rubocop:disable Metrics/ClassLength
5
5
  class << self
6
6
  extend Forwardable
7
7
 
@@ -51,8 +51,8 @@ module EnumerateIt
51
51
  list.map { |value| t(value) }
52
52
  end
53
53
 
54
- def each_value(&block)
55
- list.each(&block)
54
+ def each_value(&)
55
+ list.each(&)
56
56
  end
57
57
 
58
58
  def to_json(options = nil)
@@ -105,12 +105,17 @@ module EnumerateIt
105
105
 
106
106
  def sort_lambda
107
107
  {
108
- value: ->(_k, v) { v[0] },
109
- name: ->(k, _v) { k },
110
- translation: ->(_k, v) { translate(v[1]) }
108
+ value: ->(_k, v) { v[0] },
109
+ name: ->(k, _v) { k },
110
+ translation: ->(_k, v) { translate(v[1]) },
111
+ normalize_translation: ->(_k, v) { normalize_translation(translate(v[1])) }
111
112
  }[sort_mode]
112
113
  end
113
114
 
115
+ def normalize_translation(text)
116
+ text.unicode_normalize(:nfkd).gsub(/[^\x00-\x7F]/, '')
117
+ end
118
+
114
119
  def normalize_enumeration(values_hash)
115
120
  values_hash.each_pair do |key, value|
116
121
  values_hash[key] = [value, key] unless value.is_a? Array
@@ -1,3 +1,3 @@
1
1
  module EnumerateIt
2
- VERSION = '4.0.0'.freeze
2
+ VERSION = '4.1.0'.freeze
3
3
  end
@@ -2,10 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe EnumerateIt::Base do
4
4
  it 'creates constants for each enumeration value' do
5
- constants = [TestEnumeration::VALUE_1, TestEnumeration::VALUE_2, TestEnumeration::VALUE_3]
5
+ constants = [TestEnumeration::VALUE_1, TestEnumeration::VALUE_2, TestEnumeration::VALUE_3,
6
+ TestEnumeration::VALUE_4]
6
7
 
7
- constants.each_with_index do |constant, idx|
8
- expect(constant).to eq((idx + 1).to_s)
8
+ constants.each.with_index(1) do |constant, index|
9
+ expect(constant).to eq(index.to_s)
9
10
  end
10
11
  end
11
12
 
@@ -23,7 +24,7 @@ describe EnumerateIt::Base do
23
24
 
24
25
  describe '.list' do
25
26
  it "creates a method that returns the allowed values in the enumeration's class" do
26
- expect(TestEnumeration.list).to eq(%w[1 2 3])
27
+ expect(TestEnumeration.list).to eq(%w[1 2 3 4])
27
28
  end
28
29
 
29
30
  context 'specifying a default sort mode' do
@@ -32,40 +33,45 @@ describe EnumerateIt::Base do
32
33
  context 'by value' do
33
34
  let(:sort_mode) { :value }
34
35
 
35
- it { is_expected.to eq(%w[0 1 2 3]) }
36
+ it { is_expected.to eq(%w[0 1 2 3 4]) }
36
37
  end
37
38
 
38
39
  context 'by name' do
39
40
  let(:sort_mode) { :name }
40
41
 
41
- it { is_expected.to eq(%w[2 1 3 0]) }
42
+ it { is_expected.to eq(%w[2 4 1 3 0]) }
42
43
  end
43
44
 
44
45
  context 'by translation' do
45
46
  let(:sort_mode) { :translation }
46
47
 
47
- it { is_expected.to eq(%w[3 2 0 1]) }
48
+ it { is_expected.to eq(%w[3 2 0 1 4]) }
49
+ end
50
+
51
+ context 'by normalize translation' do
52
+ let(:sort_mode) { :normalize_translation }
53
+
54
+ it { is_expected.to eq(%w[3 4 2 0 1]) }
48
55
  end
49
56
 
50
57
  context 'by nothing' do
51
58
  let(:sort_mode) { :none }
52
59
 
53
- it { is_expected.to eq(%w[1 2 3 0]) }
60
+ it { is_expected.to eq(%w[1 2 3 4 0]) }
54
61
  end
55
62
  end
56
63
  end
57
64
 
58
65
  it 'creates a method that returns the enumeration specification' do
59
66
  expect(TestEnumeration.enumeration).to eq(
60
- value_1: ['1', 'Hey, I am 1!'],
61
- value_2: ['2', 'Hey, I am 2!'],
62
- value_3: ['3', 'Hey, I am 3!']
67
+ value_1: ['1', 'Hey, I am 1!'], value_2: ['2', 'Hey, I am 2!'],
68
+ value_3: ['3', 'Hey, I am 3!'], value_4: ['4', 'Héy, I ãm 2!']
63
69
  )
64
70
  end
65
71
 
66
72
  describe '.length' do
67
73
  it 'returns the length of the enumeration' do
68
- expect(TestEnumeration.length).to eq(3)
74
+ expect(TestEnumeration.length).to eq(4)
69
75
  end
70
76
  end
71
77
 
@@ -75,13 +81,14 @@ describe EnumerateIt::Base do
75
81
  TestEnumeration.each_translation do |translation|
76
82
  translations << translation
77
83
  end
78
- expect(translations).to eq(['Hey, I am 1!', 'Hey, I am 2!', 'Hey, I am 3!'])
84
+ expect(translations).to eq(['Hey, I am 1!', 'Hey, I am 2!', 'Hey, I am 3!', 'Héy, I ãm 2!'])
79
85
  end
80
86
  end
81
87
 
82
88
  describe '.translations' do
83
89
  it 'returns all translations' do
84
- expect(TestEnumeration.translations).to eq(['Hey, I am 1!', 'Hey, I am 2!', 'Hey, I am 3!'])
90
+ expect(TestEnumeration.translations).to eq(['Hey, I am 1!', 'Hey, I am 2!', 'Hey, I am 3!',
91
+ 'Héy, I ãm 2!'])
85
92
  end
86
93
  end
87
94
 
@@ -91,7 +98,7 @@ describe EnumerateIt::Base do
91
98
  TestEnumeration.each_key do |key|
92
99
  keys << key
93
100
  end
94
- expect(keys).to eq(%i[value_1 value_2 value_3])
101
+ expect(keys).to eq(%i[value_1 value_2 value_3 value_4])
95
102
  end
96
103
  end
97
104
 
@@ -108,7 +115,8 @@ describe EnumerateIt::Base do
108
115
  describe '.to_a' do
109
116
  it 'returns an array with the values and human representations' do
110
117
  expect(TestEnumeration.to_a)
111
- .to eq([['Hey, I am 1!', '1'], ['Hey, I am 2!', '2'], ['Hey, I am 3!', '3']])
118
+ .to eq([['Hey, I am 1!', '1'], ['Hey, I am 2!', '2'], ['Hey, I am 3!', '3'],
119
+ ['Héy, I ãm 2!', '4']])
112
120
  end
113
121
 
114
122
  it 'translates the available values' do
@@ -152,7 +160,7 @@ describe EnumerateIt::Base do
152
160
 
153
161
  describe '.to_range' do
154
162
  it "returns a Range object containing the enumeration's value interval" do
155
- expect(TestEnumeration.to_range).to eq('1'..'3')
163
+ expect(TestEnumeration.to_range).to eq('1'..'4')
156
164
  end
157
165
  end
158
166
 
@@ -206,7 +214,7 @@ describe EnumerateIt::Base do
206
214
 
207
215
  describe '.keys' do
208
216
  it 'returns a list with the keys used to define the enumeration' do
209
- expect(TestEnumeration.keys).to eq(%i[value_1 value_2 value_3])
217
+ expect(TestEnumeration.keys).to eq(%i[value_1 value_2 value_3 value_4])
210
218
  end
211
219
  end
212
220
 
@@ -235,7 +243,7 @@ describe EnumerateIt::Base do
235
243
  subject(:enumeration) { create_enumeration_class_with_sort_mode(nil) }
236
244
 
237
245
  it 'does not sort' do
238
- expect(enumeration.to_a).to eq([%w[xyz 1], %w[fgh 2], %w[abc 3], %w[jkl 0]])
246
+ expect(enumeration.to_a).to eq([%w[xyz 1], %w[fgh 2], %w[abc 3], %w[ábc 4], %w[jkl 0]])
239
247
  end
240
248
  end
241
249
 
@@ -245,25 +253,31 @@ describe EnumerateIt::Base do
245
253
  context 'by value' do
246
254
  let(:sort_mode) { :value }
247
255
 
248
- it { expect(enumeration.to_a).to eq([%w[jkl 0], %w[xyz 1], %w[fgh 2], %w[abc 3]]) }
256
+ it { expect(enumeration.to_a).to eq([%w[jkl 0], %w[xyz 1], %w[fgh 2], %w[abc 3], %w[ábc 4]]) }
249
257
  end
250
258
 
251
259
  context 'by name' do
252
260
  let(:sort_mode) { :name }
253
261
 
254
- it { expect(enumeration.to_a).to eq([%w[fgh 2], %w[xyz 1], %w[abc 3], %w[jkl 0]]) }
262
+ it { expect(enumeration.to_a).to eq([%w[fgh 2], %w[ábc 4], %w[xyz 1], %w[abc 3], %w[jkl 0]]) }
255
263
  end
256
264
 
257
265
  context 'by translation' do
258
266
  let(:sort_mode) { :translation }
259
267
 
260
- it { expect(enumeration.to_a).to eq([%w[abc 3], %w[fgh 2], %w[jkl 0], %w[xyz 1]]) }
268
+ it { expect(enumeration.to_a).to eq([%w[abc 3], %w[fgh 2], %w[jkl 0], %w[xyz 1], %w[ábc 4]]) }
269
+ end
270
+
271
+ context 'by normalize translation' do
272
+ let(:sort_mode) { :normalize_translation }
273
+
274
+ it { expect(enumeration.to_a).to eq([%w[abc 3], %w[ábc 4], %w[fgh 2], %w[jkl 0], %w[xyz 1]]) }
261
275
  end
262
276
 
263
277
  context 'by nothing' do
264
278
  let(:sort_mode) { :none }
265
279
 
266
- it { expect(enumeration.to_a).to eq([%w[xyz 1], %w[fgh 2], %w[abc 3], %w[jkl 0]]) }
280
+ it { expect(enumeration.to_a).to eq([%w[xyz 1], %w[fgh 2], %w[abc 3], %w[ábc 4], %w[jkl 0]]) }
267
281
  end
268
282
  end
269
283
 
data/spec/spec_helper.rb CHANGED
@@ -2,6 +2,7 @@ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
2
2
 
3
3
  require 'enumerate_it'
4
4
 
5
+ require 'logger' # Required by Rails 7.0 or older - https://stackoverflow.com/a/79385484/1445184
5
6
  require 'active_support/all'
6
7
  require 'active_record'
7
8
 
@@ -2,7 +2,8 @@ class TestEnumeration < EnumerateIt::Base
2
2
  associate_values(
3
3
  value_1: ['1', 'Hey, I am 1!'],
4
4
  value_2: ['2', 'Hey, I am 2!'],
5
- value_3: ['3', 'Hey, I am 3!']
5
+ value_3: ['3', 'Hey, I am 3!'],
6
+ value_4: ['4', 'Héy, I ãm 2!']
6
7
  )
7
8
  end
8
9
 
@@ -72,6 +73,7 @@ def create_enumeration_class_with_sort_mode(sort_mode)
72
73
  foo: %w[1 xyz],
73
74
  bar: %w[2 fgh],
74
75
  omg: %w[3 abc],
76
+ bra: %w[4 ábc],
75
77
  zomg: %w[0 jkl]
76
78
  )
77
79
  end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: enumerate_it
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cássio Marques
8
8
  - Lucas Caton
9
- autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2024-04-26 00:00:00.000000000 Z
11
+ date: 1980-01-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
@@ -166,7 +165,6 @@ dependencies:
166
165
  - !ruby/object:Gem::Version
167
166
  version: '2'
168
167
  description: Enumerations for Ruby with some magic powers!
169
- email:
170
168
  executables: []
171
169
  extensions: []
172
170
  extra_rdoc_files: []
@@ -188,6 +186,8 @@ files:
188
186
  - gemfiles/rails_6.1.gemfile
189
187
  - gemfiles/rails_7.0.gemfile
190
188
  - gemfiles/rails_7.1.gemfile
189
+ - gemfiles/rails_7.2.gemfile
190
+ - gemfiles/rails_8.0.gemfile
191
191
  - lib/enumerate_it.rb
192
192
  - lib/enumerate_it/base.rb
193
193
  - lib/enumerate_it/class_methods.rb
@@ -209,7 +209,6 @@ metadata:
209
209
  source_code_uri: https://github.com/lucascaton/enumerate_it
210
210
  changelog_uri: https://github.com/lucascaton/enumerate_it/releases
211
211
  rubygems_mfa_required: 'true'
212
- post_install_message:
213
212
  rdoc_options: []
214
213
  require_paths:
215
214
  - lib
@@ -224,8 +223,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
224
223
  - !ruby/object:Gem::Version
225
224
  version: '0'
226
225
  requirements: []
227
- rubygems_version: 3.5.9
228
- signing_key:
226
+ rubygems_version: 3.6.8
229
227
  specification_version: 4
230
228
  summary: Ruby Enumerations
231
229
  test_files: []