enumerations 2.5.4 → 2.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +2 -1
- data/enumerations.gemspec +1 -1
- data/lib/enumerations/base.rb +30 -1
- data/lib/enumerations/reflection.rb +1 -1
- data/lib/enumerations/version.rb +1 -1
- data/test/configuration/enumerations_test.rb +10 -0
- data/test/helpers/database_helper.rb +4 -0
- data/test/helpers/test_helper.rb +11 -0
- metadata +10 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2d4e5a6f8e18a9d70f988c555ea97c303467d965a1cf55a9e02f0406ddebdb85
|
4
|
+
data.tar.gz: 7cdec6ecd8e4ad23732ea23a5b41185b2ad1deb6cd44cedc96d73f2a28136925
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29193d63c19d102f702ecdbe16f9c1031cdd43a6a33768c977992749b6a722c7b3aaaa1e6011786c5bd9be7d20543b37b6611d930d1a205119984a9a91d6f2cc
|
7
|
+
data.tar.gz: 20b7ed5790969bb7b9ef820cc9ff89968cfef42560e46f3dbbc83b765a48bd4cef82b1d0092496ea7709db92aa4e0749d05d8b516b2d20a591807982f8c31f51
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## [v2.6.0](https://github.com/infinum/enumerations/tree/v2.6.0) (2024-10-22)
|
4
|
+
[Full Changelog](https://github.com/infinum/enumerations/compare/v2.5.4...v2.6.0)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- Add ability to specify foreign key suffix on enum class.
|
9
|
+
|
3
10
|
## [v2.5.4](https://github.com/infinum/enumerations/tree/v2.5.4) (2023-01-09)
|
4
11
|
[Full Changelog](https://github.com/infinum/enumerations/compare/v2.5.3...v2.5.4)
|
5
12
|
|
data/README.md
CHANGED
@@ -379,11 +379,12 @@ post = Post.new
|
|
379
379
|
post.status = Status.draft # => post.status_id = 1
|
380
380
|
```
|
381
381
|
|
382
|
-
If you want to configure primary key per enumeration class, you can use `primary_key=` class method:
|
382
|
+
If you want to configure primary key or foreign key suffix per enumeration class, you can use `primary_key=` and `foreign_key_suffix=` class method:
|
383
383
|
|
384
384
|
```ruby
|
385
385
|
class Status < Enumerations::Base
|
386
386
|
self.primary_key = :id
|
387
|
+
self.foreign_key_suffix = :id
|
387
388
|
|
388
389
|
value :draft, id: 1, name: 'Draft'
|
389
390
|
value :review_pending, id: 2, name: 'Review pending'
|
data/enumerations.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |s|
|
|
24
24
|
s.add_development_dependency 'pry-byebug'
|
25
25
|
s.add_development_dependency 'rake'
|
26
26
|
s.add_development_dependency 'simplecov'
|
27
|
-
s.add_development_dependency 'sqlite3'
|
27
|
+
s.add_development_dependency 'sqlite3'
|
28
28
|
|
29
29
|
s.files = `git ls-files`.split("\n")
|
30
30
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
data/lib/enumerations/base.rb
CHANGED
@@ -8,11 +8,12 @@ module Enumerations
|
|
8
8
|
extend Enumerations::FinderMethods
|
9
9
|
include Enumerations::Value
|
10
10
|
|
11
|
-
class_attribute :_values, :_symbol_index, :_primary_key
|
11
|
+
class_attribute :_values, :_symbol_index, :_primary_key, :_foreign_key_suffix
|
12
12
|
|
13
13
|
self._values = {}
|
14
14
|
self._symbol_index = {}
|
15
15
|
self._primary_key = nil
|
16
|
+
self._foreign_key_suffix = nil
|
16
17
|
|
17
18
|
# Adding new value to enumeration
|
18
19
|
#
|
@@ -108,6 +109,34 @@ module Enumerations
|
|
108
109
|
_primary_key || Enumerations.configuration.primary_key
|
109
110
|
end
|
110
111
|
|
112
|
+
# Sets foreign key suffix for enumeration class.
|
113
|
+
#
|
114
|
+
# Example:
|
115
|
+
#
|
116
|
+
# class Status < Enumeration::Base
|
117
|
+
# foreign_key_suffix = :id
|
118
|
+
# end
|
119
|
+
|
120
|
+
def self.foreign_key_suffix=(suffix)
|
121
|
+
self._foreign_key_suffix = suffix && suffix.to_sym
|
122
|
+
end
|
123
|
+
|
124
|
+
# Gets foreign key suffix for enumeration class.
|
125
|
+
#
|
126
|
+
# Example:
|
127
|
+
#
|
128
|
+
# Status.foreign_key_suffix => # nil
|
129
|
+
#
|
130
|
+
# class Status < Enumeration::Base
|
131
|
+
# foreign_key_suffix = :id
|
132
|
+
# end
|
133
|
+
#
|
134
|
+
# Status.foreign_key_suffix => # :id
|
135
|
+
#
|
136
|
+
def self.foreign_key_suffix
|
137
|
+
_foreign_key_suffix || Enumerations.configuration.foreign_key_suffix
|
138
|
+
end
|
139
|
+
|
111
140
|
def self.validate_symbol_and_primary_key(symbol, attributes)
|
112
141
|
raise Enumerations::DuplicatedSymbolError if find(symbol)
|
113
142
|
|
data/lib/enumerations/version.rb
CHANGED
@@ -47,5 +47,15 @@ module Configuration
|
|
47
47
|
|
48
48
|
assert_equal query_hash, custom_enum_id: 1
|
49
49
|
end
|
50
|
+
|
51
|
+
def test_enumerations_overrides
|
52
|
+
assert_equal :id, OverridableStatus.primary_key
|
53
|
+
assert_equal :id, OverridableStatus.foreign_key_suffix
|
54
|
+
|
55
|
+
model = OverridableModel.new
|
56
|
+
model.overridable_status = OverridableStatus.draft
|
57
|
+
|
58
|
+
assert_equal 1, model.overridable_status_id
|
59
|
+
end
|
50
60
|
end
|
51
61
|
end
|
data/test/helpers/test_helper.rb
CHANGED
@@ -40,3 +40,14 @@ class User < ActiveRecord::Base
|
|
40
40
|
enumeration :role
|
41
41
|
enumeration :status
|
42
42
|
end
|
43
|
+
|
44
|
+
class OverridableStatus < Enumerations::Base
|
45
|
+
self.primary_key = :id
|
46
|
+
self.foreign_key_suffix = :id
|
47
|
+
|
48
|
+
value :draft, id: 1
|
49
|
+
end
|
50
|
+
|
51
|
+
class OverridableModel < ActiveRecord::Base
|
52
|
+
enumeration :overridable_status
|
53
|
+
end
|
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: 2.
|
4
|
+
version: 2.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomislav Car
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Nikola Santić
|
10
10
|
- Stjepan Hadjić
|
11
11
|
- Petar Ćurković
|
12
|
-
autorequire:
|
12
|
+
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
15
|
date: 2017-09-08 00:00:00.000000000 Z
|
@@ -102,16 +102,16 @@ dependencies:
|
|
102
102
|
name: sqlite3
|
103
103
|
requirement: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
|
-
- - "
|
105
|
+
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version:
|
107
|
+
version: '0'
|
108
108
|
type: :development
|
109
109
|
prerelease: false
|
110
110
|
version_requirements: !ruby/object:Gem::Requirement
|
111
111
|
requirements:
|
112
|
-
- - "
|
112
|
+
- - ">="
|
113
113
|
- !ruby/object:Gem::Version
|
114
|
-
version:
|
114
|
+
version: '0'
|
115
115
|
description: Extends ActiveRecord with enumeration capabilites.
|
116
116
|
email:
|
117
117
|
- tomislav@infinum.hr
|
@@ -160,7 +160,7 @@ homepage: https://github.com/infinum/enumerations
|
|
160
160
|
licenses:
|
161
161
|
- MIT
|
162
162
|
metadata: {}
|
163
|
-
post_install_message:
|
163
|
+
post_install_message:
|
164
164
|
rdoc_options: []
|
165
165
|
require_paths:
|
166
166
|
- lib
|
@@ -175,23 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
175
|
- !ruby/object:Gem::Version
|
176
176
|
version: '0'
|
177
177
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
179
|
-
signing_key:
|
178
|
+
rubygems_version: 3.5.15
|
179
|
+
signing_key:
|
180
180
|
specification_version: 4
|
181
181
|
summary: Enumerations for ActiveRecord!
|
182
|
-
test_files:
|
183
|
-
- test/base_test.rb
|
184
|
-
- test/configuration/configuration.rb
|
185
|
-
- test/configuration/custom_configuration_test.rb
|
186
|
-
- test/configuration/enumerations_test.rb
|
187
|
-
- test/configuration/finder_test.rb
|
188
|
-
- test/configuration_test.rb
|
189
|
-
- test/enumerations_test.rb
|
190
|
-
- test/finder_test.rb
|
191
|
-
- test/helpers/database_helper.rb
|
192
|
-
- test/helpers/locale_helper.rb
|
193
|
-
- test/helpers/test_helper.rb
|
194
|
-
- test/locales/hr.yml
|
195
|
-
- test/reflection_test.rb
|
196
|
-
- test/translation_test.rb
|
197
|
-
- test/value_test.rb
|
182
|
+
test_files: []
|