serial_translator 2.0.1 → 2.0.2
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 +5 -5
- data/.travis.yml +7 -2
- data/lib/serial_translator.rb +6 -0
- data/lib/serial_translator/version.rb +1 -1
- data/spec/lib/serial_translator_spec.rb +6 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e8416de9ed2d78026be3343cc9af2e87fd5b1cc422d27a9c0071a4a9bb871c77
|
4
|
+
data.tar.gz: 3885221de80e12cc598214594a983182aed37aabd3da2f2ce5324c2dd24c0959
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd3e4d060f3bc25681952742562ded695f4ad10219e677407633e5e865e76aa4afba47dc9116981a2b0453e2a128fc6fb9a66663432ee3270a1c575d6a9130eb
|
7
|
+
data.tar.gz: 827a71095c2db3bb562731dda31217fa0b95c1d680b02463e6463221fa2865aeb6f26ba40c2ba46be5698b92e17b1ec9b87eb8bed12dbfa5b084cc267004ecf7
|
data/.travis.yml
CHANGED
data/lib/serial_translator.rb
CHANGED
@@ -14,6 +14,9 @@ module SerialTranslator
|
|
14
14
|
attr_writer :current_translation_locale, :translation_fallback
|
15
15
|
end
|
16
16
|
|
17
|
+
class InvalidLocaleError < StandardError
|
18
|
+
end
|
19
|
+
|
17
20
|
module ClassMethods
|
18
21
|
attr_reader :serial_translator_attributes
|
19
22
|
|
@@ -39,6 +42,9 @@ module SerialTranslator
|
|
39
42
|
# Define the normal setter, that respects the
|
40
43
|
# current translation locale
|
41
44
|
define_method "#{attr_name}=" do |value|
|
45
|
+
unless I18n.available_locales.include?(current_translation_locale)
|
46
|
+
raise InvalidLocaleError, "current_translation_locale #{current_translation_locale.inspect} is not a member of I18n.available_locales: #{I18n.available_locales.inspect}"
|
47
|
+
end
|
42
48
|
__send__(:"#{attr_name}_translations_will_change!")
|
43
49
|
translations = translations_for(attr_name)
|
44
50
|
if value.present?
|
@@ -48,6 +48,12 @@ describe SerialTranslator do
|
|
48
48
|
expect(object.title_translations).to eq({ de: 'Deutsch' })
|
49
49
|
end
|
50
50
|
|
51
|
+
it 'raises an error if current translation is not an I18n locale' do
|
52
|
+
object.current_translation_locale = :foobar
|
53
|
+
expect { object.title = 'Deutsch' }.to raise_error(SerialTranslator::InvalidLocaleError)
|
54
|
+
expect(object.title_translations).to eq({})
|
55
|
+
end
|
56
|
+
|
51
57
|
it 'nil removes the value for the current text locale' do
|
52
58
|
object.title_translations = { de: 'Deutsch' }
|
53
59
|
object.current_translation_locale = :de
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: serial_translator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- betterplace development team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-11-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -183,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
183
183
|
version: '0'
|
184
184
|
requirements: []
|
185
185
|
rubyforge_project:
|
186
|
-
rubygems_version: 2.6
|
186
|
+
rubygems_version: 2.7.6
|
187
187
|
signing_key:
|
188
188
|
specification_version: 4
|
189
189
|
summary: Translate attribute values without additional models
|