serial_translator 2.0.3 → 2.0.4

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: e67a98e574e71655f1d1c1de15b35356db3bd0501e06c464d207591a2d8a4da6
4
- data.tar.gz: c2ab2da70fdb53ab500912f5ec061e6a504765735a5a518be73869b0839eb2e4
3
+ metadata.gz: 16540a0794dd2e5b30066bd6db4a42a7db4976d91f9cd82753bd5b210aa6a565
4
+ data.tar.gz: 1299a9f6bfbc957cf8795cbe2d5d0ce4130b1822005c60a41d5933d2d1941eca
5
5
  SHA512:
6
- metadata.gz: c98bb5a850f094b31691f12165095187db6e5df31cc2a46624df1059136c9b58cd8fa3b9115b34d37f336d3ee06c80f90a5fe1b9067abe036029f65236f19458
7
- data.tar.gz: a33d2d1793c60dfc441f4c7ced0397cc09bcddfba6904fedc49d63c2e74034d3adc260c9662eea9905c2f5a9e06ccf085395ef760080f711281a8be2466752d3
6
+ metadata.gz: 1d18b78243cf079e150907d76fa004b92992fd1e9dc99a7cfda20f3946176a8a119b128562ba09334af0088a4ae8e66d1f7091c745705671fdf618d25608c923
7
+ data.tar.gz: e85688152b1ca0a2b980684e845f41953ac4551c9a97558bfdad95dd166dea6931259586ea0162fa0b87b02bdfa89ab382d00ea577e305099b7fbee1ce3ebeef
@@ -0,0 +1,29 @@
1
+ # based on https://github.com/rails/rails/blob/4a78dcb/.github/workflows/rubocop.yml
2
+
3
+ name: rubocop linting
4
+
5
+ on: [push, pull_request]
6
+
7
+ jobs:
8
+ build:
9
+ runs-on: ubuntu-latest
10
+
11
+ steps:
12
+ - uses: actions/checkout@v2
13
+ - name: Set up Ruby
14
+ uses: ruby/setup-ruby@v1
15
+ with:
16
+ ruby-version: 2.7
17
+ - name: Cache gems
18
+ uses: actions/cache@v1
19
+ with:
20
+ path: vendor/bundle
21
+ key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
22
+ restore-keys: |
23
+ ${{ runner.os }}-rubocop-
24
+ - name: Install gems
25
+ run: |
26
+ bundle config path vendor/bundle
27
+ bundle install --jobs 4 --retry 3
28
+ - name: Run rubocop
29
+ run: bundle exec rubocop --lint
@@ -0,0 +1,22 @@
1
+ name: tests
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby: [ '2.7', 'ruby-head' ]
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+ - name: Set up Ruby ${{ matrix.ruby }}
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - name: Install dependencies
20
+ run: bundle install --jobs 4
21
+ - name: Test with Rake
22
+ run: bundle exec rake
data/.rubocop.yml ADDED
@@ -0,0 +1,61 @@
1
+ # usage: `rubocop --lint`
2
+
3
+ AllCops:
4
+ NewCops: enable
5
+
6
+ # disable some linters that are not so likely to indicate bugs
7
+
8
+ Lint/AmbiguousAssignment:
9
+ Enabled: false
10
+ Lint/AmbiguousBlockAssociation:
11
+ Enabled: false
12
+ Lint/AmbiguousOperator:
13
+ Enabled: false
14
+ Lint/AmbiguousRegexpLiteral:
15
+ Enabled: false
16
+ Lint/AssignmentInCondition:
17
+ Enabled: false
18
+ Lint/ConstantDefinitionInBlock:
19
+ Enabled: false
20
+ Lint/ConstantResolution:
21
+ Enabled: false
22
+ Lint/DuplicateBranch:
23
+ Enabled: false
24
+ Lint/EmptyBlock:
25
+ Enabled: false
26
+ Lint/EmptyClass:
27
+ Enabled: false
28
+ Lint/EmptyConditionalBody:
29
+ Enabled: false
30
+ Lint/EmptyExpression:
31
+ Enabled: false
32
+ Lint/EmptyFile:
33
+ Enabled: false
34
+ Lint/EmptyWhen:
35
+ Enabled: false
36
+ Lint/EnsureReturn:
37
+ Enabled: false
38
+ Lint/Loop:
39
+ Enabled: false
40
+ Lint/MissingSuper:
41
+ Enabled: false
42
+ Lint/MixedRegexpCaptureTypes:
43
+ Enabled: false
44
+ Lint/NumberConversion:
45
+ Enabled: false
46
+ Lint/ParenthesesAsGroupedExpression:
47
+ Enabled: false
48
+ Lint/RedundantStringCoercion:
49
+ Enabled: false
50
+ Lint/ShadowedArgument:
51
+ Enabled: false
52
+ Lint/ShadowedException:
53
+ Enabled: false
54
+ Lint/ShadowingOuterLocalVariable:
55
+ Enabled: false
56
+ Lint/SuppressedException:
57
+ Enabled: false
58
+ Lint/UnusedBlockArgument:
59
+ Enabled: false
60
+ Lint/UnusedMethodArgument:
61
+ Enabled: false
data/.tool-versions CHANGED
@@ -1 +1 @@
1
- ruby 3.0.0
1
+ ruby 3.0.2
data/README.md CHANGED
@@ -1,15 +1,10 @@
1
1
  # SerialTranslator
2
2
 
3
3
  [![Gem Version](https://badge.fury.io/rb/serial_translator.svg)](http://badge.fury.io/rb/serial_translator)
4
- [![Build Status](https://travis-ci.org/betterplace/serial_translator.svg)](https://travis-ci.org/betterplace/serial_translator)
5
- [![Dependency Status](https://gemnasium.com/betterplace/serial_translator.svg)](https://gemnasium.com/betterplace/serial_translator)
4
+ [![Build Status](https://github.com/betterplace/serial_translator/workflows/tests/badge.svg)](https://github.com/betterplace/serial_translator/actions)
6
5
 
7
6
  Translate ActiveRecord object attributes without the use of additional models.
8
7
 
9
- ## Changes from 1.* to 2.*
10
-
11
- `serial_translator` will now store all translations in JSON format per default rather than in YAML. However, it is still able to read YAML serialized translations and will convert them in the background.
12
-
13
8
  ## Installation
14
9
 
15
10
  Add it to your Gemfile:
@@ -67,9 +62,6 @@ class BlogPost < ActiveRecord::Base
67
62
  end
68
63
  ```
69
64
 
70
-
71
-
72
-
73
65
  ## Contributing
74
66
 
75
67
  1. Fork it
@@ -4,8 +4,9 @@ module SerialTranslator
4
4
  translations = record.__send__("#{attribute}_translations")&.values || []
5
5
  translations = [nil] if translations.empty?
6
6
  translations.each do |value|
7
- next if options[:allow_blank] && value.to_s == '' ||
8
- options[:allow_nil] && value.nil?
7
+ next if (options[:allow_blank] && value.to_s == '') ||
8
+ (options[:allow_nil] && value.nil?)
9
+
9
10
  validate_translation(record, attribute, value)
10
11
  end
11
12
  end
@@ -1,3 +1,3 @@
1
1
  module SerialTranslator
2
- VERSION = "2.0.3"
2
+ VERSION = "2.0.4"
3
3
  end
@@ -47,6 +47,9 @@ module SerialTranslator
47
47
  end
48
48
  __send__(:"#{attr_name}_translations_will_change!")
49
49
  translations = translations_for(attr_name)
50
+
51
+ value&.scrub!('')
52
+
50
53
  if value.present?
51
54
  translations[current_translation_locale] = value
52
55
  else
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency 'rspec'
26
26
  spec.add_development_dependency 'rspec-collection_matchers'
27
27
  spec.add_development_dependency 'json', '~>2'
28
+ spec.add_development_dependency 'rubocop'
28
29
  spec.add_development_dependency 'simplecov'
29
30
  spec.add_development_dependency 'sqlite3'
30
31
  end
@@ -42,6 +42,16 @@ describe SerialTranslator do
42
42
  end
43
43
 
44
44
  describe 'writing an attribute' do
45
+ it 'sets the value for the current text locale even with weird utf8 contents' do
46
+ badly_encoded_string = "Ügnore ünvalîd \xFF UTF-8"
47
+ expect(badly_encoded_string.valid_encoding?).to eq false
48
+
49
+ object.current_translation_locale = :de
50
+ object.title = badly_encoded_string
51
+
52
+ expect(object.title_translations).to eq({ de: 'Ügnore ünvalîd UTF-8' })
53
+ end
54
+
45
55
  it 'sets the value for the current text locale' do
46
56
  object.current_translation_locale = :de
47
57
  object.title = 'Deutsch'
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.3
4
+ version: 2.0.4
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: 2021-02-06 00:00:00.000000000 Z
11
+ date: 2021-10-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: simplecov
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -143,10 +157,12 @@ executables: []
143
157
  extensions: []
144
158
  extra_rdoc_files: []
145
159
  files:
160
+ - ".github/workflows/lint.yml"
161
+ - ".github/workflows/tests.yml"
146
162
  - ".gitignore"
147
163
  - ".rspec"
164
+ - ".rubocop.yml"
148
165
  - ".tool-versions"
149
- - ".travis.yml"
150
166
  - ".utilsrc"
151
167
  - Gemfile
152
168
  - LICENSE.txt
@@ -183,7 +199,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
183
199
  - !ruby/object:Gem::Version
184
200
  version: '0'
185
201
  requirements: []
186
- rubygems_version: 3.2.3
202
+ rubygems_version: 3.2.29
187
203
  signing_key:
188
204
  specification_version: 4
189
205
  summary: Translate attribute values without additional models
data/.travis.yml DELETED
@@ -1,12 +0,0 @@
1
- before_install:
2
- - gem update --system
3
- - gem update bundler
4
-
5
- rvm:
6
- - 2.7
7
- - 3.0
8
-
9
- notifications:
10
- disabled: false
11
- recipients:
12
- - developers@betterplace.org