enumerations 2.3.3 → 2.4.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: b3236e6559134898d597bcdd10d713f1e8b0221ebc86c40c51b99ee99b9a902f
4
- data.tar.gz: a16037b68fca739949c3952260e44cde3ad904de8072ea4f9fe9216870bba39b
3
+ metadata.gz: 7a43aa264af10522517e6bfcf47daee1ea28d382d2187ca12690d19f2018781b
4
+ data.tar.gz: ba01b7f7c44242da5a792839038a3967719e9a2bd6edc9ff8dc73cf66f1d090e
5
5
  SHA512:
6
- metadata.gz: 375ca1a05df8bf65c6ecf4086fd9bb0a4db797398079a9b414aea37851f7ed1bcf56f88b2acfeb2e509a9b4f674b9ce45b2c807377acb8ed5253d981625f5134
7
- data.tar.gz: 4e02e59780bc7321acf18233b784dfc0b3f1d45e9b8d97e7b43c2a3c99e8c9b688adb6a5a15d884b4d2d0def1b9918bd824c7936f84a55eb38de55d5779f46d4
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 = :id
311
- config.foreign_key_suffix = :id
310
+ config.primary_key = :id
311
+ config.foreign_key_suffix = :id
312
+ config.translate_attributes = true
312
313
  end
313
314
  ```
314
315
 
@@ -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.3.6'
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 = nil
20
- @foreign_key_suffix = nil
22
+ @primary_key = nil
23
+ @foreign_key_suffix = nil
24
+ @translate_attributes = true
21
25
  end
22
26
  end
23
27
  end
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module Enumerations
2
- VERSION = '2.3.3'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -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.3.3
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.3.6
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.3.6
114
+ version: 1.4.0
115
115
  description: Extends ActiveRecord with enumeration capabilites.
116
116
  email:
117
117
  - tomislav@infinum.hr