enumerations 2.3.3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/enumerations.gemspec +1 -1
- data/lib/enumerations/configuration.rb +6 -2
- data/lib/enumerations/value.rb +2 -0
- data/lib/enumerations/version.rb +1 -1
- data/test/translation_test.rb +9 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7a43aa264af10522517e6bfcf47daee1ea28d382d2187ca12690d19f2018781b
|
4
|
+
data.tar.gz: ba01b7f7c44242da5a792839038a3967719e9a2bd6edc9ff8dc73cf66f1d090e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4032983040ac1421779fc12c5433635e572073c6b2da731294de2696dc8074aa4c42677d5831b9e3e02f9ae6deecf0d2a6d91e792d6a1c360ff20cec05a9a41d
|
7
|
+
data.tar.gz: 7dbd89ebab4b368b5971fb011ab386bc5ad25d6670d8f3c9225c0ccf44a5e353d8903ec997e970ef1fafd01b3c5ad7fd03e8d76a5f407e6440fd50cf47e2bba7
|
data/README.md
CHANGED
@@ -265,7 +265,7 @@ Status.other.name? # => false
|
|
265
265
|
Translations
|
266
266
|
=====
|
267
267
|
|
268
|
-
**Enumerations** uses power of I18n API to enable you to create a locale file
|
268
|
+
**Enumerations** uses power of I18n API (if translate_attributes configuration is set to true) to enable you to create a locale file
|
269
269
|
for enumerations like this:
|
270
270
|
|
271
271
|
```yaml
|
@@ -307,8 +307,9 @@ Example of configuration:
|
|
307
307
|
# config/initializers/enumerations.rb
|
308
308
|
|
309
309
|
Enumerations.configure do |config|
|
310
|
-
config.primary_key
|
311
|
-
config.foreign_key_suffix
|
310
|
+
config.primary_key = :id
|
311
|
+
config.foreign_key_suffix = :id
|
312
|
+
config.translate_attributes = true
|
312
313
|
end
|
313
314
|
```
|
314
315
|
|
data/enumerations.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.add_development_dependency 'pry-byebug'
|
24
24
|
s.add_development_dependency 'rake'
|
25
25
|
s.add_development_dependency 'simplecov'
|
26
|
-
s.add_development_dependency 'sqlite3', '~> 1.
|
26
|
+
s.add_development_dependency 'sqlite3', '~> 1.4.0'
|
27
27
|
|
28
28
|
s.files = `git ls-files`.split("\n")
|
29
29
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Enumerations
|
2
4
|
def self.configuration
|
3
5
|
@configuration ||= Configuration.new
|
@@ -14,10 +16,12 @@ module Enumerations
|
|
14
16
|
class Configuration
|
15
17
|
attr_accessor :primary_key
|
16
18
|
attr_accessor :foreign_key_suffix
|
19
|
+
attr_accessor :translate_attributes
|
17
20
|
|
18
21
|
def initialize
|
19
|
-
@primary_key
|
20
|
-
@foreign_key_suffix
|
22
|
+
@primary_key = nil
|
23
|
+
@foreign_key_suffix = nil
|
24
|
+
@translate_attributes = true
|
21
25
|
end
|
22
26
|
end
|
23
27
|
end
|
data/lib/enumerations/value.rb
CHANGED
@@ -66,6 +66,8 @@ module Enumerations
|
|
66
66
|
end
|
67
67
|
|
68
68
|
def translate_attribute(key, locale)
|
69
|
+
return @attributes[key].to_s unless Enumerations.configuration.translate_attributes
|
70
|
+
|
69
71
|
I18n.t(key, scope: [:enumerations, self.class.name.demodulize.underscore, symbol],
|
70
72
|
default: @attributes[key].to_s,
|
71
73
|
locale: locale)
|
data/lib/enumerations/version.rb
CHANGED
data/test/translation_test.rb
CHANGED
@@ -91,4 +91,13 @@ class TranslationTest < Minitest::Test
|
|
91
91
|
|
92
92
|
assert_nil status
|
93
93
|
end
|
94
|
+
|
95
|
+
def test_turn_of_translate
|
96
|
+
status = Status.find(:draft)
|
97
|
+
Enumerations.configuration.translate_attributes = false
|
98
|
+
name = status.name
|
99
|
+
Enumerations.configuration.translate_attributes = true
|
100
|
+
|
101
|
+
assert_equal name, 'Draft'
|
102
|
+
end
|
94
103
|
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.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tomislav Car
|
@@ -104,14 +104,14 @@ dependencies:
|
|
104
104
|
requirements:
|
105
105
|
- - "~>"
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
version: 1.
|
107
|
+
version: 1.4.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.
|
114
|
+
version: 1.4.0
|
115
115
|
description: Extends ActiveRecord with enumeration capabilites.
|
116
116
|
email:
|
117
117
|
- tomislav@infinum.hr
|