enumerate_it 3.3.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: 9b90c459a95ec327cbd699627f1d3138534973d110341a9578fad036b64f8fe6
4
- data.tar.gz: f9fe475a8601491e9ebe8b908460630655109350aca3c53b7b346ce77ebcee0a
3
+ metadata.gz: 0e0e2aa1d31c14c5e310f50feb06824c19e7bffa49d08ab1f29d8f3a9b45e32d
4
+ data.tar.gz: a6e1642362885b5e306c713dd54c859452c2392bb17c012e039c84bd8878f9e9
5
5
  SHA512:
6
- metadata.gz: 7a93a55f4c43f1f18e4d3162f7de7edef091c7bf1b94b331e1251f041d9fc41d7df7ca1e36ac210eb989890e3f8f9da1a0bddc374e546decc72f9f0cbe6e8f98
7
- data.tar.gz: 59e02b301cb593851fbd05c203a132bcbd178039538c2a5a090547d4df68f829e770d1fda80cfbd176a304b99b4239c1a0ac8c802f0cb30de44d1c2bc935b7c1
6
+ metadata.gz: ea12eb1fe75185a0525f0580906391e37d5b540bcc09f273a2cac96c7e168994b184f549c54cd04af9940452355fd159d449c199db5855cdf0b0b03c209dd8f6
7
+ data.tar.gz: f2793a073ffb559e162970e069bc5136d08b03e74dd77f885c1f27d041c48c7d25fb83de9c982bcfb4e1105149635272db5ef8ee4d86c228666c87318baae765
@@ -9,58 +9,24 @@ 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
16
+ - 3.4
19
17
  gemfile:
20
- - gemfiles/rails_5.0.gemfile
21
- - gemfiles/rails_5.1.gemfile
22
- - gemfiles/rails_5.2.gemfile
23
18
  - gemfiles/rails_6.0.gemfile
24
19
  - gemfiles/rails_6.1.gemfile
25
20
  - gemfiles/rails_7.0.gemfile
26
21
  - gemfiles/rails_7.1.gemfile
22
+ - gemfiles/rails_7.2.gemfile
23
+ - gemfiles/rails_8.0.gemfile
27
24
  exclude:
28
- # Rails < 6 does not support Ruby 3+:
29
- # https://github.com/rails/rails/issues/40938#issuecomment-751357907
25
+ # Rails 8 requires Ruby 3.2 or newer
30
26
  - 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
27
+ gemfile: gemfiles/rails_8.0.gemfile
38
28
  - 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
29
+ gemfile: gemfiles/rails_8.0.gemfile
64
30
 
65
31
  env:
66
32
  BUNDLE_GEMFILE: "${{ matrix.gemfile }}"
@@ -77,7 +43,7 @@ jobs:
77
43
  bundler-cache: true
78
44
 
79
45
  - name: Rubocop
80
- if: ${{ matrix.ruby == '3.3' }}
46
+ if: ${{ matrix.ruby == '3.4' }}
81
47
  run: "bundle exec rubocop"
82
48
 
83
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: 2.5
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[5.0 5.1 5.2 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,17 +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
- if Gem::Version.new(rails_version) <= Gem::Version.new(5.0)
17
- gem 'sqlite3', '< 1.4'
16
+ if Gem::Version.new(rails_version) > Gem::Version.new(7.0)
17
+ gem 'sqlite3'
18
18
  else
19
- # v2.x isn't yet working. See: https://github.com/sparklemotion/sqlite3-ruby/issues/529
20
- gem 'sqlite3', '< 2'
19
+ gem 'sqlite3', '< 2' # Rails 6.x and 7.0 require sqlite3 v1.x
21
20
  end
22
21
 
23
- # elsif Gem::Version.new(RUBY_VERSION) < '3'
24
- # gem 'sqlite3', '< 2'
25
- # else
26
- # gem 'sqlite3'
27
- # end
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
28
29
  end
29
30
  end
data/Gemfile.lock CHANGED
@@ -1,107 +1,110 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- enumerate_it (3.3.0)
5
- activesupport (>= 5.0.7.2)
4
+ enumerate_it (4.1.0)
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.0.5)
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.2)
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.4.19
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,33 +4,41 @@ 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 flexible way.
10
+ **EnumerateIt** helps you declare and use enumerations in a very simple and
11
+ flexible way.
12
12
 
13
- ### 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?
14
14
 
15
15
  Firstly, although **EnumerateIt** works well with **Rails**, it isn't required!
16
- It means you can add it to any **Ruby** project! Secondly, you can
17
- [define your enumerations in classes](https://github.com/lucascaton/enumerate_it#creating-enumerations),
18
- 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! 😀
19
19
 
20
20
  ---
21
21
 
22
22
  <!-- Tocer[start]: Auto-generated, don't remove. -->
23
23
 
24
- - [Installation](#installation)
25
- - [Using with Rails](#using-with-rails)
26
- - [Creating enumerations](#creating-enumerations)
27
- - [Sorting enumerations](#sorting-enumerations)
28
- - [Using enumerations](#using-enumerations)
29
- - [FAQ](#faq)
30
- - [I18n](#i18n)
31
- - [Translate a name-spaced enumeration](#translate-a-name-spaced-enumeration)
32
- - [Handling a legacy database](#handling-a-legacy-database)
33
- - [Changelog](#changelog)
24
+ ## Table of Contents
25
+
26
+ - [Installation](#installation)
27
+ - [Using with Rails](#using-with-rails)
28
+ - [Creating enumerations](#creating-enumerations)
29
+ - [Sorting enumerations](#sorting-enumerations)
30
+ - [Using enumerations](#using-enumerations)
31
+ - [FAQ](#faq)
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)
36
+ - [I18n](#i18n)
37
+ - [Translate a namespaced enumeration](#translate-a-namespaced-enumeration)
38
+ - [Handling a legacy database](#handling-a-legacy-database)
39
+ - [Changelog](#changelog)
40
+ - [Note on Patches/Pull Requests](#note-on-patchespull-requests)
41
+ - [Copyright](#copyright)
34
42
 
35
43
  <!-- Tocer[finish]: Auto-generated, don't remove. -->
36
44
 
@@ -56,10 +64,11 @@ rails generate enumerate_it:enum --help
56
64
 
57
65
  ## Creating enumerations
58
66
 
59
- Enumerations are created as classes and you should put them inside `app/enumerations` folder.
67
+ Enumerations are created as classes and should be placed inside the
68
+ `app/enumerations` folder.
60
69
 
61
- You can pass an array of symbols, so that the respective value for each symbol will be the
62
- 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:
63
72
 
64
73
  ```ruby
65
74
  class RelationshipStatus < EnumerateIt::Base
@@ -71,9 +80,9 @@ class RelationshipStatus < EnumerateIt::Base
71
80
  end
72
81
  ```
73
82
 
74
- This will create some nice stuff:
83
+ This will generate some nice stuff:
75
84
 
76
- * Each enumeration's value will turn into a constant:
85
+ - Constants for each enumeration value:
77
86
 
78
87
  ```ruby
79
88
  RelationshipStatus::SINGLE
@@ -83,68 +92,67 @@ This will create some nice stuff:
83
92
  #=> 'married'
84
93
  ```
85
94
 
86
- * You can retrieve a list with all the enumeration codes:
95
+ - A list of all enumeration codes:
87
96
 
88
97
  ```ruby
89
98
  RelationshipStatus.list
90
99
  #=> ['divorced', 'married', 'single']
91
100
  ```
92
101
 
93
- * You can retrieve a JSON with all the enumeration codes:
102
+ - A JSON representation:
94
103
 
95
104
  ```ruby
96
105
  RelationshipStatus.to_json
97
106
  #=> "[{\"value\":\"divorced\",\"label\":\"Divorced\"},{\"value\":\"married\", ...
98
107
  ```
99
108
 
100
- * You can get an array of options, ready to use with the `select`, `select_tag`, etc. family of
101
- Rails helpers.
109
+ - An array of options for Rails helpers, such as `select`, `select_tag`, etc.:
102
110
 
103
111
  ```ruby
104
112
  RelationshipStatus.to_a
105
113
  #=> [['Divorced', 'divorced'], ['Married', 'married'], ['Single', 'single']]
106
114
  ```
107
115
 
108
- * You can retrieve a list with values for a group of enumeration constants.
116
+ - You can retrieve a list with values for a group of enumeration constants.
109
117
 
110
118
  ```ruby
111
119
  RelationshipStatus.values_for %w(MARRIED SINGLE)
112
120
  #=> ['married', 'single']
113
121
  ```
114
122
 
115
- * You can retrieve the value for a specific enumeration constant:
123
+ - You can retrieve the value for a specific enumeration constant:
116
124
 
117
125
  ```ruby
118
126
  RelationshipStatus.value_for('MARRIED')
119
127
  #=> 'married'
120
128
  ```
121
129
 
122
- * You can retrieve the symbol used to declare a specific enumeration value:
130
+ - You can retrieve the symbol used to declare a specific enumeration value:
123
131
 
124
132
  ```ruby
125
133
  RelationshipStatus.key_for(RelationshipStatus::MARRIED)
126
134
  #=> :married
127
135
  ```
128
136
 
129
- * You can iterate over the list of the enumeration's values:
137
+ - You can iterate over the list of the enumeration's values:
130
138
 
131
139
  ```ruby
132
140
  RelationshipStatus.each_value { |value| ... }
133
141
  ```
134
142
 
135
- * You can iterate over the list of the enumeration's translations:
143
+ - You can iterate over the list of the enumeration's translations:
136
144
 
137
145
  ```ruby
138
146
  RelationshipStatus.each_translation { |translation| ... }
139
147
  ```
140
148
 
141
- * You can also retrieve all the translations of the enumeration:
149
+ - You can also retrieve all the translations of the enumeration:
142
150
 
143
151
  ```ruby
144
152
  RelationshipStatus.translations
145
153
  ```
146
154
 
147
- * You can ask for the enumeration's length:
155
+ - You can ask for the enumeration's length:
148
156
 
149
157
  ```ruby
150
158
  RelationshipStatus.length
@@ -153,11 +161,10 @@ This will create some nice stuff:
153
161
 
154
162
  ### Sorting enumerations
155
163
 
156
- When calling methods like `to_a`, `to_json` and `list`, the returned values will be sorted by
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:
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.
160
166
 
167
+ You can override this with the `sort_by` class method:
161
168
 
162
169
  ```ruby
163
170
  class RelationshipStatus < EnumerateIt::Base
@@ -167,18 +174,20 @@ class RelationshipStatus < EnumerateIt::Base
167
174
  end
168
175
  ```
169
176
 
170
- The `sort_by` method accepts one of the following values:
177
+ Accepted values for `sort_by`:
171
178
 
172
- | Value | Behavior |
173
- | :------------- | :------------------------------------------------------------------------------------------- |
174
- | `:none` | The default behavior, will return values in order that was passed to `associate_values` call |
175
- | `:name` | Will sort the returned values based on the name of each enumeration option |
176
- | `:translation` | will sort the returned values based on their translations |
177
- | `: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)) |
178
186
 
179
187
  ## Using enumerations
180
188
 
181
- 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:
182
191
 
183
192
  ```ruby
184
193
  # ActiveRecord instance
@@ -197,14 +206,14 @@ class Person
197
206
  end
198
207
  ```
199
208
 
200
- > **Note:** **EnumerateIt** will try to load an enumeration class based on the camelized attribute
201
- > name. If you have a different name, you can specify it by using the `with` option:
209
+ > **Note:** If the enumeration class name differs from the attribute name, use
210
+ > the `with` option:
202
211
  >
203
212
  > `has_enumeration_for :relationship_status, with: RelationshipStatus`
204
213
 
205
214
  This will create:
206
215
 
207
- * A "humanized" version of the hash's key to humanize the attribute's value:
216
+ - A "humanized" version of the hash's key to humanize the attribute's value:
208
217
 
209
218
  ```ruby
210
219
  p = Person.new
@@ -213,8 +222,8 @@ This will create:
213
222
  #=> 'Divorced'
214
223
  ```
215
224
 
216
- * A translation for your options, if you include a locale to represent it
217
- (see more in the [I18n section](#i18n)).
225
+ - A translation for your options, if you include a locale to represent it (see
226
+ more in the [I18n section](#i18n)).
218
227
 
219
228
  ```ruby
220
229
  p = Person.new
@@ -223,14 +232,16 @@ This will create:
223
232
  #=> 'Divorciado'
224
233
  ```
225
234
 
226
- * The associated enumerations, which can be retrieved with the `enumerations` class method:
235
+ - The associated enumerations, which can be retrieved with the `enumerations`
236
+ class method:
227
237
 
228
238
  ```ruby
229
239
  Person.enumerations
230
240
  #=> { relationship_status: RelationshipStatus }
231
241
  ```
232
242
 
233
- * A helper method for each enumeration option, if you pass the `create_helpers` option as `true`:
243
+ - A helper method for each enumeration option, if you pass the `create_helpers`
244
+ option as `true`:
234
245
 
235
246
  ```ruby
236
247
  class Person < ApplicationRecord
@@ -247,8 +258,9 @@ This will create:
247
258
  #=> false
248
259
  ```
249
260
 
250
- It's also possible to "namespace" the created helper methods, passing a hash to the `create_helpers`
251
- option. This can be useful when two or more of the enumerations used share the same constants:
261
+ It's also possible to "namespace" the created helper methods, passing a hash
262
+ to the `create_helpers` option. This can be useful when two or more of the
263
+ enumerations used share the same constants:
252
264
 
253
265
  ```ruby
254
266
  class Person < ApplicationRecord
@@ -266,8 +278,8 @@ This will create:
266
278
  #=> false
267
279
  ```
268
280
 
269
- You can define polymorphic behavior for the enumeration values, so you can define a class for each
270
- of them:
281
+ You can define polymorphic behavior for the enumeration values, so you can
282
+ define a class for each of them:
271
283
 
272
284
  ```ruby
273
285
  class RelationshipStatus < EnumerateIt::Base
@@ -312,8 +324,8 @@ This will create:
312
324
  p.relationship_status_mode.saturday_night
313
325
  ```
314
326
 
315
- The `create_helpers` also creates some mutator helper methods, that can be used to change the
316
- attribute's value.
327
+ The `create_helpers` also creates some mutator helper methods, that can be
328
+ used to change the attribute's value.
317
329
 
318
330
  ```ruby
319
331
  p = Person.new
@@ -323,7 +335,8 @@ This will create:
323
335
  #=> true
324
336
  ```
325
337
 
326
- * A scope method for each enumeration option if you pass the `create_scopes` option as `true`:
338
+ - A scope method for each enumeration option if you pass the `create_scopes`
339
+ option as `true`:
327
340
 
328
341
  ```ruby
329
342
  class Person < ApplicationRecord
@@ -345,7 +358,7 @@ This will create:
345
358
  Person.relationship_status_married.to_sql
346
359
  ```
347
360
 
348
- * An inclusion validation (if your class can manage validations and responds to
361
+ - An inclusion validation (if your class can manage validations and responds to
349
362
  `validates_inclusion_of`):
350
363
 
351
364
  ```ruby
@@ -360,7 +373,7 @@ This will create:
360
373
  #=> 'is not included in the list'
361
374
  ```
362
375
 
363
- * A presence validation (if your class can manage validations and responds to
376
+ - A presence validation (if your class can manage validations and responds to
364
377
  `validates_presence_of` and you pass the `required` options as `true`):
365
378
 
366
379
  ```ruby
@@ -375,7 +388,8 @@ This will create:
375
388
  #=> "can't be blank"
376
389
  ```
377
390
 
378
- If you pass the `skip_validation` option as `true`, it will not create any validations:
391
+ If you pass the `skip_validation` option as `true`, it will not create any
392
+ validations:
379
393
 
380
394
  ```ruby
381
395
  class Person < ApplicationRecord
@@ -387,15 +401,16 @@ This will create:
387
401
  #=> true
388
402
  ```
389
403
 
390
- Remember that you can add validations to any kind of class and not only `ActiveRecord` ones.
404
+ Remember that you can add validations to any kind of class and not only
405
+ `ActiveRecord` ones.
391
406
 
392
407
  ## FAQ
393
408
 
394
409
  #### Why define enumerations outside the class that uses them?
395
410
 
396
- * It's clearer.
397
- * You can add behaviour to the enumeration class.
398
- * You can reuse the enumeration inside other classes.
411
+ - It's clearer.
412
+ - You can add behavior to the enumeration class.
413
+ - You can reuse the enumeration inside other classes.
399
414
 
400
415
  #### Can I use `enumerate_it` gem without Rails?
401
416
 
@@ -403,20 +418,22 @@ You sure can! 😄
403
418
 
404
419
  #### What versions of Ruby and Rails are supported?
405
420
 
406
- * **Ruby**: `2.5+`
407
- * **Rails** `5.0+`
421
+ - **Ruby**: `3.0+`
422
+ - **Rails**: `6.0+`
408
423
 
409
424
  All versions are tested via
410
425
  [GitHub Actions](https://github.com/lucascaton/enumerate_it/blob/HEAD/.github/workflows/ci.yml).
411
426
 
412
427
  #### Can I set a value to always be at the end of a sorted list?
413
428
 
414
- Yes, [see more details here](https://github.com/lucascaton/enumerate_it/issues/60).
429
+ Yes,
430
+ [see more details here](https://github.com/lucascaton/enumerate_it/issues/60).
415
431
 
416
432
  ## I18n
417
433
 
418
- I18n lookup is provided on both `_humanized` and `Enumeration#to_a` methods, given the hash key is
419
- a Symbol. The I18n strings are located on `enumerations.<enumeration_name>.<key>`:
434
+ I18n lookup is provided for both `_humanized` and `Enumeration#to_a` methods,
435
+ given the hash key is a Symbol. The I18n strings are located on
436
+ `enumerations.<enumeration_name>.<key>`:
420
437
 
421
438
  ```yaml
422
439
  # Your locale file
@@ -452,24 +469,24 @@ RelationshipStatus.t(status)
452
469
  #=> 'Casado'
453
470
  ```
454
471
 
455
- ### Translate a name-spaced enumeration
472
+ ### Translate a namespaced enumeration
456
473
 
457
- In order to translate an enumeration in a specific namespace (say `Design::Color`),
458
- you can add the following:
474
+ In order to translate an enumeration in a specific namespace (say
475
+ `Design::Color`), use the following structure:
459
476
 
460
477
  ```yaml
461
478
  pt-BR:
462
479
  enumerations:
463
- 'design/color':
480
+ "design/color":
464
481
  blue: Azul
465
482
  red: Vermelho
466
483
  ```
467
484
 
468
485
  ## Handling a legacy database
469
486
 
470
- **EnumerateIt** can help you build a Rails application around a legacy database which was filled
471
- with those small and unchangeable tables used to create foreign key constraints everywhere, like the
472
- following example:
487
+ **EnumerateIt** can help you build a Rails application around a legacy database
488
+ which was filled with those small and unchangeable tables used to create foreign
489
+ key constraints everywhere, like the following example:
473
490
 
474
491
  ```sql
475
492
  Table "public.relationship_status"
@@ -491,14 +508,16 @@ code | description
491
508
  3 | Divorced
492
509
  ```
493
510
 
494
- You might also have something like a `users` table with a `relationship_status` column and a foreign
495
- key pointing to the `relationship_status` table.
511
+ You might also have something like a `users` table with a `relationship_status`
512
+ column and a foreign key pointing to the `relationship_status` table.
496
513
 
497
- While this is a good thing from the database normalization perspective, managing these values in
498
- tests is very hard. Doing database joins just to get the description of some value is absurd.
499
- And, more than this, referencing them in the code using
500
- [magic numbers](https://en.wikipedia.org/wiki/Magic_number_(programming)) was terrible and
501
- meaningless: what does it mean when we say that someone or something is `2`?
514
+ While this is a good thing from the database normalization perspective, managing
515
+ these values in tests is very hard. Doing database joins just to get the
516
+ description of some value is absurd. And, more than this, referencing them in
517
+ the code using
518
+ [magic numbers](<https://en.wikipedia.org/wiki/Magic_number_(programming)>) was
519
+ terrible and meaningless: what does it mean when we say that someone or
520
+ something is `2`?
502
521
 
503
522
  To solve this, you can pass a **hash** to your enumeration values:
504
523
 
@@ -526,14 +545,17 @@ you can see them on the [releases page](../../releases).
526
545
 
527
546
  ## Note on Patches/Pull Requests
528
547
 
529
- * Fork the project.
530
- * Make your feature addition or bug fix.
531
- * Add tests for it. This is important so we don't break it in a future version unintentionally.
532
- * [Optional] Run the tests against a specific Gemfile: `$ bundle exec appraisal rails_7.0 rake spec`.
533
- * Run the tests against all supported versions: `$ bundle exec rake` (or `$ bundle exec wwtd`)
534
- * Commit, but please do not mess with `Rakefile`, version, or history.
535
- * Send a Pull Request. Bonus points for topic branches.
548
+ - Fork the project.
549
+ - Make your feature addition or bug fix.
550
+ - Add tests for it. This is important so we don't break it in a future version
551
+ unintentionally.
552
+ - [Optional] Run the tests against a specific Gemfile:
553
+ `bundle exec appraisal rails_8.0 rake spec`.
554
+ - Run the tests against all supported versions: `bundle exec rake`
555
+ - Commit, but please do not mess with `Rakefile`, version, or history.
556
+ - Send a Pull Request. Bonus points for topic branches.
536
557
 
537
558
  ## Copyright
538
559
 
539
- Copyright (c) 2010-2024 Cássio Marques and Lucas Caton. See `LICENSE` file for details.
560
+ Copyright (c) 2010-2025 Cássio Marques and Lucas Caton. See `LICENSE` file for
561
+ 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 = '>= 2.5.8'
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', '>= 5.0.7.2'
23
+ gem.add_dependency 'activesupport', '>= 6.0.0'
24
24
 
25
25
  gem.add_development_dependency 'activerecord'
26
26
  gem.add_development_dependency 'appraisal'
@@ -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: '../'
@@ -2,8 +2,8 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'activerecord', '~> 5.1.7'
6
- gem 'activesupport', '~> 5.1.7'
7
- gem 'sqlite3', '< 2'
5
+ gem 'activerecord', '~> 7.2.2.1'
6
+ gem 'activesupport', '~> 7.2.2.1'
7
+ gem 'sqlite3'
8
8
 
9
9
  gemspec path: '../'
@@ -2,8 +2,8 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'activerecord', '~> 5.2.8.1'
6
- gem 'activesupport', '~> 5.2.8.1'
7
- gem 'sqlite3', '< 2'
5
+ gem 'activerecord', '~> 8.0.2'
6
+ gem 'activesupport', '~> 8.0.2'
7
+ gem 'sqlite3'
8
8
 
9
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 = '3.3.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,10 +2,11 @@ $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
 
8
- Dir['./spec/support/**/*.rb'].sort.each { |f| require f }
9
+ Dir['./spec/support/**/*.rb'].each { |f| require f }
9
10
 
10
11
  I18n.config.enforce_available_locales = false
11
12
  I18n.load_path = Dir['spec/i18n/*.yml']
@@ -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: 3.3.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-21 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
@@ -17,14 +16,14 @@ dependencies:
17
16
  requirements:
18
17
  - - ">="
19
18
  - !ruby/object:Gem::Version
20
- version: 5.0.7.2
19
+ version: 6.0.0
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
24
  - - ">="
26
25
  - !ruby/object:Gem::Version
27
- version: 5.0.7.2
26
+ version: 6.0.0
28
27
  - !ruby/object:Gem::Dependency
29
28
  name: activerecord
30
29
  requirement: !ruby/object:Gem::Requirement
@@ -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: []
@@ -184,13 +182,12 @@ files:
184
182
  - README.md
185
183
  - Rakefile
186
184
  - enumerate_it.gemspec
187
- - gemfiles/rails_5.0.gemfile
188
- - gemfiles/rails_5.1.gemfile
189
- - gemfiles/rails_5.2.gemfile
190
185
  - gemfiles/rails_6.0.gemfile
191
186
  - gemfiles/rails_6.1.gemfile
192
187
  - gemfiles/rails_7.0.gemfile
193
188
  - gemfiles/rails_7.1.gemfile
189
+ - gemfiles/rails_7.2.gemfile
190
+ - gemfiles/rails_8.0.gemfile
194
191
  - lib/enumerate_it.rb
195
192
  - lib/enumerate_it/base.rb
196
193
  - lib/enumerate_it/class_methods.rb
@@ -212,7 +209,6 @@ metadata:
212
209
  source_code_uri: https://github.com/lucascaton/enumerate_it
213
210
  changelog_uri: https://github.com/lucascaton/enumerate_it/releases
214
211
  rubygems_mfa_required: 'true'
215
- post_install_message:
216
212
  rdoc_options: []
217
213
  require_paths:
218
214
  - lib
@@ -220,15 +216,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
220
216
  requirements:
221
217
  - - ">="
222
218
  - !ruby/object:Gem::Version
223
- version: 2.5.8
219
+ version: 3.0.0
224
220
  required_rubygems_version: !ruby/object:Gem::Requirement
225
221
  requirements:
226
222
  - - ">="
227
223
  - !ruby/object:Gem::Version
228
224
  version: '0'
229
225
  requirements: []
230
- rubygems_version: 3.5.3
231
- signing_key:
226
+ rubygems_version: 3.6.8
232
227
  specification_version: 4
233
228
  summary: Ruby Enumerations
234
229
  test_files: []
@@ -1,9 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source 'https://rubygems.org'
4
-
5
- gem 'activerecord', '~> 5.0.7.2'
6
- gem 'activesupport', '~> 5.0.7.2'
7
- gem 'sqlite3', '< 1.4'
8
-
9
- gemspec path: '../'