enumerations 2.5.3 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7415435429c08e2093220592c091dffca83b50fd26f6d71836873594da483778
4
- data.tar.gz: 63538f83e93d43926f2401297c213a03c814efb667d96259f8f86cfa241072e3
3
+ metadata.gz: 2d4e5a6f8e18a9d70f988c555ea97c303467d965a1cf55a9e02f0406ddebdb85
4
+ data.tar.gz: 7cdec6ecd8e4ad23732ea23a5b41185b2ad1deb6cd44cedc96d73f2a28136925
5
5
  SHA512:
6
- metadata.gz: dfcb47a129cd32afa78c25897aa681bef271266c878ba9fc077df12ed15543ebdab1f97e71c580adb9e19523bbf3287b3ec0a46a52b247f42030c4f9ade31b1d
7
- data.tar.gz: 2dbce2808dcadd1cb3e0b16193b9f66e567846c8d9dca89478d30edc6c1b583e8b8b9e8443e08ec162e7e30dc78423cf7b90edf5de41de2b64722b664785a1d2
6
+ metadata.gz: 29193d63c19d102f702ecdbe16f9c1031cdd43a6a33768c977992749b6a722c7b3aaaa1e6011786c5bd9be7d20543b37b6611d930d1a205119984a9a91d6f2cc
7
+ data.tar.gz: 20b7ed5790969bb7b9ef820cc9ff89968cfef42560e46f3dbbc83b765a48bd4cef82b1d0092496ea7709db92aa4e0749d05d8b516b2d20a591807982f8c31f51
data/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
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
+
10
+ ## [v2.5.4](https://github.com/infinum/enumerations/tree/v2.5.4) (2023-01-09)
11
+ [Full Changelog](https://github.com/infinum/enumerations/compare/v2.5.3...v2.5.4)
12
+
13
+ **Implemented enhancements:**
14
+
15
+ - Add MIT license file.
16
+
3
17
  ## [v2.5.3](https://github.com/infinum/enumerations/tree/v2.5.3) (2022-02-02)
4
18
  [Full Changelog](https://github.com/infinum/enumerations/compare/v2.5.2...v2.5.3)
5
19
 
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 Infinum
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
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
@@ -7,6 +7,7 @@ Gem::Specification.new do |s|
7
7
  s.summary = 'Enumerations for ActiveRecord!'
8
8
  s.description = 'Extends ActiveRecord with enumeration capabilites.'
9
9
  s.homepage = 'https://github.com/infinum/enumerations'
10
+ s.license = 'MIT'
10
11
 
11
12
  s.authors = [
12
13
  'Tomislav Car', 'Nikica Jokić', 'Nikola Santić', 'Stjepan Hadjić', 'Petar Ćurković'
@@ -23,7 +24,7 @@ Gem::Specification.new do |s|
23
24
  s.add_development_dependency 'pry-byebug'
24
25
  s.add_development_dependency 'rake'
25
26
  s.add_development_dependency 'simplecov'
26
- s.add_development_dependency 'sqlite3', '~> 1.4.0'
27
+ s.add_development_dependency 'sqlite3'
27
28
 
28
29
  s.files = `git ls-files`.split("\n")
29
30
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -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
 
@@ -22,7 +22,7 @@ module Enumerations
22
22
  private
23
23
 
24
24
  def default_foreign_key_name
25
- [name, Enumerations.configuration.foreign_key_suffix].compact.join('_')
25
+ [name, enumerator_class.foreign_key_suffix].compact.join('_')
26
26
  end
27
27
  end
28
28
  end
@@ -1,3 +1,3 @@
1
1
  module Enumerations
2
- VERSION = '2.5.3'.freeze
2
+ VERSION = '2.6.0'.freeze
3
3
  end
@@ -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
@@ -17,4 +17,8 @@ ActiveRecord::Schema.define do
17
17
  t.integer :custom_enum_id
18
18
  t.integer :custom_enum
19
19
  end
20
+
21
+ create_table :overridable_models, force: true do |t|
22
+ t.integer :overridable_status_id
23
+ end
20
24
  end
@@ -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.5.3
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: 1.4.0
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: 1.4.0
114
+ version: '0'
115
115
  description: Extends ActiveRecord with enumeration capabilites.
116
116
  email:
117
117
  - tomislav@infinum.hr
@@ -128,6 +128,7 @@ files:
128
128
  - ".rubocop.yml"
129
129
  - CHANGELOG.md
130
130
  - Gemfile
131
+ - LICENSE
131
132
  - MIGRATE.md
132
133
  - README.md
133
134
  - Rakefile
@@ -156,9 +157,10 @@ files:
156
157
  - test/translation_test.rb
157
158
  - test/value_test.rb
158
159
  homepage: https://github.com/infinum/enumerations
159
- licenses: []
160
+ licenses:
161
+ - MIT
160
162
  metadata: {}
161
- post_install_message:
163
+ post_install_message:
162
164
  rdoc_options: []
163
165
  require_paths:
164
166
  - lib
@@ -173,8 +175,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
173
175
  - !ruby/object:Gem::Version
174
176
  version: '0'
175
177
  requirements: []
176
- rubygems_version: 3.3.3
177
- signing_key:
178
+ rubygems_version: 3.5.15
179
+ signing_key:
178
180
  specification_version: 4
179
181
  summary: Enumerations for ActiveRecord!
180
182
  test_files: []