enumerations 2.6.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -1
- data/CHANGELOG.md +13 -0
- data/enumerations.gemspec +5 -2
- data/lib/enumerations/base.rb +3 -7
- data/lib/enumerations/version.rb +3 -1
- data/test/enumerations_test.rb +11 -1
- data/test/helpers/database_helper.rb +6 -0
- data/test/helpers/test_helper.rb +18 -3
- metadata +19 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1754e7d5747cf0444bf6b19ba7915f8517eecc6d847dc76af169442bb8d31aed
|
|
4
|
+
data.tar.gz: e00f367b9c16a09155ee517163a6803afbed756d6ae24ea2bf945c5b062cbc01
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c43fe2bc75f47f1bd53c17f676a2648a2be94ea1598d42af96df85cb31add41db2cf0faf9a8b2bca47a3bb9fda2849f52be4076386fddbcacafe395e410a9cc2
|
|
7
|
+
data.tar.gz: 9a858dcb732e394343c0f323fcf41433a9caf695d9d6d300f813cdb98f4d5bb4574c9c60eb46fe9be8005f374c7eed67f2a7604a655aa046f83c4bb701a083cf
|
data/.github/workflows/test.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## [v3.0.0](https://github.com/infinum/enumerations/tree/v3.0.0) (2026-01-16)
|
|
4
|
+
[Full Changelog](https://github.com/infinum/enumerations/compare/v2.6.0...v3.0.0)
|
|
5
|
+
|
|
6
|
+
**Breaking change:**
|
|
7
|
+
|
|
8
|
+
- enumeration classes with overridden `to_s` method might not work as expected anymore
|
|
9
|
+
(previously, overriding `to_s` would affect the value saved to the database, now it doesn't anymore)
|
|
10
|
+
|
|
11
|
+
**Implemented enhancements:**
|
|
12
|
+
|
|
13
|
+
- Drop support for ruby 2.6 and 2.7, only versions '>= 3.0' are now supported
|
|
14
|
+
- Resolve `ActiveSupport::Multibyte::Chars` deprecation warning
|
|
15
|
+
|
|
3
16
|
## [v2.6.0](https://github.com/infinum/enumerations/tree/v2.6.0) (2024-10-22)
|
|
4
17
|
[Full Changelog](https://github.com/infinum/enumerations/compare/v2.5.4...v2.6.0)
|
|
5
18
|
|
data/enumerations.gemspec
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('lib/enumerations/version', __dir__)
|
|
2
4
|
|
|
3
5
|
Gem::Specification.new do |s|
|
|
4
6
|
s.name = 'enumerations'
|
|
@@ -8,8 +10,9 @@ Gem::Specification.new do |s|
|
|
|
8
10
|
s.description = 'Extends ActiveRecord with enumeration capabilites.'
|
|
9
11
|
s.homepage = 'https://github.com/infinum/enumerations'
|
|
10
12
|
s.license = 'MIT'
|
|
13
|
+
s.required_ruby_version = '>= 3.0'
|
|
11
14
|
|
|
12
|
-
s.authors
|
|
15
|
+
s.authors = [
|
|
13
16
|
'Tomislav Car', 'Nikica Jokić', 'Nikola Santić', 'Stjepan Hadjić', 'Petar Ćurković'
|
|
14
17
|
]
|
|
15
18
|
|
data/lib/enumerations/base.rb
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'active_support/core_ext/class/attribute'
|
|
2
4
|
require 'active_support/core_ext/string/inflections'
|
|
3
5
|
require 'enumerations/value'
|
|
4
6
|
require 'enumerations/finder_methods'
|
|
5
7
|
|
|
6
8
|
module Enumerations
|
|
7
|
-
class Base <
|
|
9
|
+
class Base < String
|
|
8
10
|
extend Enumerations::FinderMethods
|
|
9
11
|
include Enumerations::Value
|
|
10
12
|
|
|
@@ -162,11 +164,5 @@ module Enumerations
|
|
|
162
164
|
|
|
163
165
|
create_instance_methods
|
|
164
166
|
end
|
|
165
|
-
|
|
166
|
-
private
|
|
167
|
-
|
|
168
|
-
def chars(string)
|
|
169
|
-
string
|
|
170
|
-
end
|
|
171
167
|
end
|
|
172
168
|
end
|
data/lib/enumerations/version.rb
CHANGED
data/test/enumerations_test.rb
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require_relative 'helpers/test_helper'
|
|
2
4
|
require 'enumerations/errors'
|
|
3
5
|
|
|
4
|
-
class EnumerationsTest < Minitest::Test
|
|
6
|
+
class EnumerationsTest < Minitest::Test # rubocop:disable Metrics/ClassLength
|
|
5
7
|
def test_reflect_on_all_enumerations
|
|
6
8
|
enumerations = Post.reflect_on_all_enumerations
|
|
7
9
|
|
|
@@ -157,4 +159,12 @@ class EnumerationsTest < Minitest::Test
|
|
|
157
159
|
user = User.new(role: nil)
|
|
158
160
|
assert_nil user.role
|
|
159
161
|
end
|
|
162
|
+
|
|
163
|
+
def test_type_cast_when_saving_value_to_database
|
|
164
|
+
client = ApiClient.new(api_client_permission: ApiClientPermission.people_first_name)
|
|
165
|
+
client.save
|
|
166
|
+
|
|
167
|
+
# overriding to_s doesn't have an effect on the value saved to the database
|
|
168
|
+
assert_equal 'people_first_name', client[:api_client_permission]
|
|
169
|
+
end
|
|
160
170
|
end
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'logger'
|
|
2
4
|
|
|
3
5
|
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
|
@@ -21,4 +23,8 @@ ActiveRecord::Schema.define do
|
|
|
21
23
|
create_table :overridable_models, force: true do |t|
|
|
22
24
|
t.integer :overridable_status_id
|
|
23
25
|
end
|
|
26
|
+
|
|
27
|
+
create_table :api_clients, force: true do |t|
|
|
28
|
+
t.string :api_client_permission
|
|
29
|
+
end
|
|
24
30
|
end
|
data/test/helpers/test_helper.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
require 'simplecov'
|
|
2
4
|
SimpleCov.start
|
|
3
5
|
|
|
@@ -10,9 +12,9 @@ require_relative 'database_helper'
|
|
|
10
12
|
require_relative 'locale_helper'
|
|
11
13
|
|
|
12
14
|
class Status < Enumerations::Base
|
|
13
|
-
values draft:
|
|
14
|
-
review_pending:
|
|
15
|
-
published:
|
|
15
|
+
values draft: { id: 1, name: 'Draft' },
|
|
16
|
+
review_pending: { id: 2, name: 'Review pending' },
|
|
17
|
+
published: { id: 3, name: 'Published' }
|
|
16
18
|
|
|
17
19
|
value :none, id: 4, name: 'None', visible: true, deleted: false
|
|
18
20
|
value :deleted, id: 5, deleted: true
|
|
@@ -29,6 +31,19 @@ class Role < Enumerations::Base
|
|
|
29
31
|
end
|
|
30
32
|
end
|
|
31
33
|
|
|
34
|
+
class ApiClientPermission < Enumerations::Base
|
|
35
|
+
value :people_first_name, id: 'people.first_name'
|
|
36
|
+
value :people_last_name, id: 'people.last_name'
|
|
37
|
+
|
|
38
|
+
def to_s
|
|
39
|
+
id
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class ApiClient < ActiveRecord::Base
|
|
44
|
+
enumeration :api_client_permission
|
|
45
|
+
end
|
|
46
|
+
|
|
32
47
|
class Post < ActiveRecord::Base
|
|
33
48
|
enumeration :status
|
|
34
49
|
enumeration :different_status, foreign_key: :some_other_status, class_name: 'Status'
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: enumerations
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tomislav Car
|
|
@@ -9,7 +9,6 @@ authors:
|
|
|
9
9
|
- Nikola Santić
|
|
10
10
|
- Stjepan Hadjić
|
|
11
11
|
- Petar Ćurković
|
|
12
|
-
autorequire:
|
|
13
12
|
bindir: bin
|
|
14
13
|
cert_chain: []
|
|
15
14
|
date: 2017-09-08 00:00:00.000000000 Z
|
|
@@ -160,7 +159,6 @@ homepage: https://github.com/infinum/enumerations
|
|
|
160
159
|
licenses:
|
|
161
160
|
- MIT
|
|
162
161
|
metadata: {}
|
|
163
|
-
post_install_message:
|
|
164
162
|
rdoc_options: []
|
|
165
163
|
require_paths:
|
|
166
164
|
- lib
|
|
@@ -168,15 +166,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
168
166
|
requirements:
|
|
169
167
|
- - ">="
|
|
170
168
|
- !ruby/object:Gem::Version
|
|
171
|
-
version: '0'
|
|
169
|
+
version: '3.0'
|
|
172
170
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
173
171
|
requirements:
|
|
174
172
|
- - ">="
|
|
175
173
|
- !ruby/object:Gem::Version
|
|
176
174
|
version: '0'
|
|
177
175
|
requirements: []
|
|
178
|
-
rubygems_version: 3.
|
|
179
|
-
signing_key:
|
|
176
|
+
rubygems_version: 3.6.4
|
|
180
177
|
specification_version: 4
|
|
181
178
|
summary: Enumerations for ActiveRecord!
|
|
182
|
-
test_files:
|
|
179
|
+
test_files:
|
|
180
|
+
- test/base_test.rb
|
|
181
|
+
- test/configuration/configuration.rb
|
|
182
|
+
- test/configuration/custom_configuration_test.rb
|
|
183
|
+
- test/configuration/enumerations_test.rb
|
|
184
|
+
- test/configuration/finder_test.rb
|
|
185
|
+
- test/configuration_test.rb
|
|
186
|
+
- test/enumerations_test.rb
|
|
187
|
+
- test/finder_test.rb
|
|
188
|
+
- test/helpers/database_helper.rb
|
|
189
|
+
- test/helpers/locale_helper.rb
|
|
190
|
+
- test/helpers/test_helper.rb
|
|
191
|
+
- test/locales/hr.yml
|
|
192
|
+
- test/reflection_test.rb
|
|
193
|
+
- test/translation_test.rb
|
|
194
|
+
- test/value_test.rb
|