translate_enum 0.1.3 → 0.2.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: cf98e01d928af2ec5e49e4eac061ca0c17eec85d2c2677177f73297de6b6649c
4
- data.tar.gz: c70c0b9ff2d8703887866a24585ee3ff29a3a558501023005f634619f3b511b6
3
+ metadata.gz: 150acd115290af056b50713506f5a273ceac5404a61d9504afae6af9c29d7cc4
4
+ data.tar.gz: ccd7d29f340f1e336271ffd282a984a9e322639d5ddf4a381c3fa5eed49d0006
5
5
  SHA512:
6
- metadata.gz: ef036edee634238f02923fef5b0d413c78bfab1a41ec0316c06bb9a2ad9a51f7f36f8194ad7f0631fec0568f9600550e6aaee35372a7fff8d151f0b4e07cbc41
7
- data.tar.gz: f1fc1a47322f038b7b62cbdb0af0901caa30353c85b675b70c3b0fa3d3a779f1243804228cd74515a94eb168f19275df47c23041fe70e63a2c041d63c307eafd
6
+ metadata.gz: 0abc8185f91ddcd8b7afee3492eeb812bc007a5af0bc969bb8a9d66a924b200d5dcfe555845e3700d7e59dc03db2ec882af31f2cb60c7b486f76e028919b0cff
7
+ data.tar.gz: ad53963f3780993a3d4b56c20006a8fc8fe4a7942b9157733635a2e714125abf4f3fcdb052a8dbc8d63c3000518c4d6e9b9e7a530201e731c3c8a6fd8eebe34f
@@ -0,0 +1,62 @@
1
+ name: CI
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ rspec:
7
+ runs-on: ubuntu-latest
8
+
9
+ strategy:
10
+ matrix:
11
+ ruby-version: [3.0, 2.7, 2.6]
12
+
13
+ steps:
14
+ - uses: actions/checkout@v2
15
+
16
+ - name: Set up Ruby ${{ matrix.ruby-version }}
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: ${{ matrix.ruby-version }}
20
+
21
+ - name: Cache gems
22
+ uses: actions/cache@v1
23
+ with:
24
+ path: vendor/bundle
25
+ key: ${{ runner.os }}-${{ matrix.ruby-version }}-bundler-${{ hashFiles('**/Gemfile.lock') }}
26
+ restore-keys: |
27
+ ${{ runner.os }}-${{ matrix.ruby-version }}-bundler-
28
+
29
+ - name: Install gems
30
+ run: |
31
+ bundle config path vendor/bundle
32
+ bundle install --jobs 4 --retry 3
33
+
34
+ - name: Run tests
35
+ run: bundle exec rspec
36
+
37
+ rubocop:
38
+ runs-on: ubuntu-latest
39
+
40
+ steps:
41
+ - uses: actions/checkout@v2
42
+
43
+ - name: Set up Ruby
44
+ uses: ruby/setup-ruby@v1
45
+ with:
46
+ ruby-version: 3.0
47
+
48
+ - name: Cache gems
49
+ uses: actions/cache@v1
50
+ with:
51
+ path: vendor/bundle
52
+ key: ${{ runner.os }}-bundler-${{ hashFiles('**/Gemfile.lock') }}
53
+ restore-keys: |
54
+ ${{ runner.os }}-bundler-
55
+
56
+ - name: Install gems
57
+ run: |
58
+ bundle config path vendor/bundle
59
+ bundle install --jobs 4 --retry 3
60
+
61
+ - name: Run Rubocop
62
+ run: bundle exec rubocop
data/.rubocop.yml ADDED
@@ -0,0 +1,413 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ AutoCorrect: false
6
+ SuggestExtensions: false
7
+ Exclude:
8
+ - 'click_house.gemspec'
9
+ - 'bin/*'
10
+ - 'spec/**/*'
11
+ - 'vendor/**/*'
12
+ TargetRubyVersion: 2.6
13
+ Bundler/OrderedGems:
14
+ Enabled: false
15
+
16
+ # ============================== Gemspec ======================
17
+ Gemspec/DeprecatedAttributeAssignment:
18
+ Enabled: true
19
+ Gemspec/RequireMFA: # new in 1.23
20
+ Enabled: true
21
+
22
+ # =============================== Performance =======================
23
+ Performance/AncestorsInclude:
24
+ Enabled: true
25
+ Performance/BigDecimalWithNumericArgument:
26
+ Enabled: true
27
+ Performance/RedundantSortBlock:
28
+ Enabled: true
29
+ Performance/RedundantStringChars:
30
+ Enabled: true
31
+ Performance/ReverseFirst:
32
+ Enabled: true
33
+ Performance/SortReverse:
34
+ Enabled: true
35
+ Performance/Squeeze:
36
+ Enabled: true
37
+ Performance/StringInclude:
38
+ Enabled: true
39
+ Performance/Sum:
40
+ Enabled: true
41
+ Performance/ArraySemiInfiniteRangeSlice:
42
+ Enabled: true
43
+ Performance/BlockGivenWithExplicitBlock:
44
+ Enabled: true
45
+ Performance/CollectionLiteralInLoop:
46
+ Enabled: true
47
+ Performance/ConstantRegexp:
48
+ Enabled: true
49
+ Performance/MethodObjectAsBlock:
50
+ Enabled: false
51
+ Performance/RedundantEqualityComparisonBlock:
52
+ Enabled: true
53
+ Performance/RedundantSplitRegexpArgument:
54
+ Enabled: true
55
+ Performance/MapCompact:
56
+ Enabled: true
57
+ Performance/ConcurrentMonotonicTime: # new in 1.12
58
+ Enabled: true
59
+ Performance/StringIdentifierArgument: # new in 1.13
60
+ Enabled: true
61
+
62
+ # ============================== Metrics ============================
63
+ Metrics/ClassLength:
64
+ Max: 180
65
+ Metrics/BlockLength:
66
+ Enabled: true
67
+ Metrics/MethodLength:
68
+ Max: 25
69
+ Metrics/AbcSize:
70
+ Max: 40
71
+
72
+ # ============================== Naming =============================
73
+ Naming/PredicateName:
74
+ ForbiddenPrefixes:
75
+ - is_
76
+ Naming/FileName:
77
+ Enabled: true
78
+ Exclude:
79
+ - 'Gemfile'
80
+ Naming/MethodParameterName:
81
+ Enabled: false
82
+ Naming/AccessorMethodName:
83
+ Enabled: false
84
+ Naming/InclusiveLanguage:
85
+ Enabled: true
86
+ Naming/BlockForwarding: # new in 1.24
87
+ Enabled: true
88
+
89
+ # ============================== Layout =============================
90
+ Layout/LineLength:
91
+ Max: 140
92
+ Layout/HashAlignment:
93
+ EnforcedHashRocketStyle: key
94
+ EnforcedColonStyle: key
95
+ Layout/ParameterAlignment:
96
+ EnforcedStyle: with_fixed_indentation
97
+ Layout/CaseIndentation:
98
+ EnforcedStyle: case
99
+ IndentOneStep: false
100
+ Layout/MultilineMethodCallIndentation:
101
+ Enabled: true
102
+ EnforcedStyle: indented
103
+ Layout/SpaceBeforeBlockBraces:
104
+ EnforcedStyle: space
105
+ EnforcedStyleForEmptyBraces: space
106
+ Layout/EmptyLines:
107
+ Enabled: true
108
+ Layout/EmptyLineAfterMagicComment:
109
+ Enabled: false
110
+ Layout/EmptyLinesAroundBlockBody:
111
+ Enabled: true
112
+ Layout/EndAlignment:
113
+ EnforcedStyleAlignWith: variable
114
+ Layout/FirstHashElementIndentation:
115
+ EnforcedStyle: consistent
116
+ Layout/HeredocIndentation:
117
+ Enabled: false
118
+ Layout/RescueEnsureAlignment:
119
+ Enabled: false
120
+ Layout/EmptyLinesAroundAttributeAccessor:
121
+ Enabled: true
122
+ Layout/SpaceAroundMethodCallOperator:
123
+ Enabled: true
124
+ Layout/SpaceBeforeBrackets:
125
+ Enabled: true
126
+ Layout/LineEndStringConcatenationIndentation:
127
+ Enabled: true
128
+ Layout/LineContinuationLeadingSpace: # new in 1.31
129
+ Enabled: true
130
+ Layout/LineContinuationSpacing: # new in 1.31
131
+ Enabled: true
132
+
133
+ # ============================== Style ==============================
134
+ Style/RescueModifier:
135
+ Enabled: true
136
+ Style/PercentLiteralDelimiters:
137
+ PreferredDelimiters:
138
+ default: '[]'
139
+ '%i': '[]'
140
+ '%w': '[]'
141
+ Exclude:
142
+ - 'config/routes.rb'
143
+ Style/StringLiterals:
144
+ Enabled: true
145
+ Style/AsciiComments:
146
+ Enabled: false
147
+ Style/Copyright:
148
+ Enabled: false
149
+ Style/SafeNavigation:
150
+ Enabled: false
151
+ Style/Lambda:
152
+ Enabled: false
153
+ Style/Alias:
154
+ Enabled: true
155
+ EnforcedStyle: prefer_alias_method
156
+ Style/ClassAndModuleChildren:
157
+ Enabled: true
158
+ EnforcedStyle: nested
159
+ Style/TrailingCommaInArrayLiteral:
160
+ Enabled: true
161
+ EnforcedStyleForMultiline: no_comma
162
+ Style/RescueStandardError:
163
+ Enabled: true
164
+ EnforcedStyle: explicit
165
+ Style/InverseMethods:
166
+ AutoCorrect: false
167
+ Enabled: true
168
+ Style/IfUnlessModifier:
169
+ Enabled: false
170
+ Style/SpecialGlobalVars:
171
+ Enabled: false
172
+ Style/BlockComments:
173
+ Enabled: false
174
+ Style/GuardClause:
175
+ Enabled: false
176
+ Style/TrailingCommaInHashLiteral:
177
+ Enabled: false
178
+ Style/ExponentialNotation:
179
+ Enabled: true
180
+ Style/HashEachMethods:
181
+ Enabled: true
182
+ Style/HashTransformKeys:
183
+ Enabled: true
184
+ Style/HashTransformValues:
185
+ Enabled: true
186
+ Style/RedundantFetchBlock:
187
+ Enabled: true
188
+ Style/RedundantRegexpCharacterClass:
189
+ Enabled: true
190
+ Style/RedundantRegexpEscape:
191
+ Enabled: true
192
+ Style/SlicingWithRange:
193
+ Enabled: true
194
+ Style/AccessorGrouping:
195
+ Enabled: false
196
+ Style/ArrayCoercion:
197
+ Enabled: true
198
+ Style/BisectedAttrAccessor:
199
+ Enabled: true
200
+ Style/CaseLikeIf:
201
+ Enabled: true
202
+ Style/HashAsLastArrayItem:
203
+ Enabled: true
204
+ Style/HashLikeCase:
205
+ Enabled: true
206
+ Style/RedundantAssignment:
207
+ Enabled: true
208
+ Style/RedundantFileExtensionInRequire:
209
+ Enabled: true
210
+ Style/ExplicitBlockArgument:
211
+ Enabled: true
212
+ Style/GlobalStdStream:
213
+ Enabled: true
214
+ Style/OptionalBooleanParameter:
215
+ Enabled: true
216
+ Style/SingleArgumentDig:
217
+ Enabled: true
218
+ Style/StringConcatenation:
219
+ Enabled: true
220
+ Style/ClassEqualityComparison:
221
+ Enabled: true
222
+ Style/CombinableLoops:
223
+ Enabled: true
224
+ Style/KeywordParametersOrder:
225
+ Enabled: false
226
+ Style/RedundantSelfAssignment:
227
+ Enabled: true
228
+ Style/SoleNestedConditional:
229
+ Enabled: true
230
+ Style/ArgumentsForwarding:
231
+ Enabled: true
232
+ Style/CollectionCompact:
233
+ Enabled: true
234
+ Style/DocumentDynamicEvalDefinition:
235
+ Enabled: false
236
+ Style/NegatedIfElseCondition:
237
+ Enabled: true
238
+ Style/NilLambda:
239
+ Enabled: true
240
+ Style/SwapValues:
241
+ Enabled: true
242
+ Style/RedundantArgument:
243
+ Enabled: true
244
+ Style/HashExcept:
245
+ Enabled: true
246
+ Style/EndlessMethod:
247
+ Enabled: true
248
+ Style/IfWithBooleanLiteralBranches:
249
+ Enabled: true
250
+ Style/HashConversion:
251
+ Enabled: true
252
+ Style/Documentation:
253
+ Enabled: false
254
+ Style/InPatternThen:
255
+ Enabled: true
256
+ Style/MultilineInPatternThen:
257
+ Enabled: true
258
+ Style/QuotedSymbols:
259
+ Enabled: true
260
+ Style/StringChars:
261
+ Enabled: true
262
+ Style/EmptyHeredoc: # new in 1.32
263
+ Enabled: true
264
+ Style/EnvHome: # new in 1.29
265
+ Enabled: true
266
+ Style/FetchEnvVar: # new in 1.28
267
+ Enabled: true
268
+ Style/FileRead: # new in 1.24
269
+ Enabled: true
270
+ Style/FileWrite: # new in 1.24
271
+ Enabled: true
272
+ Style/MagicCommentFormat: # new in 1.35
273
+ Enabled: true
274
+ Style/MapCompactWithConditionalBlock: # new in 1.30
275
+ Enabled: true
276
+ Style/MapToHash: # new in 1.24
277
+ Enabled: true
278
+ Style/NestedFileDirname: # new in 1.26
279
+ Enabled: true
280
+ Style/NumberedParameters: # new in 1.22
281
+ Enabled: true
282
+ Style/NumberedParametersLimit: # new in 1.22
283
+ Enabled: true
284
+ Style/ObjectThen: # new in 1.28
285
+ Enabled: true
286
+ Style/OpenStructUse: # new in 1.23
287
+ Enabled: true
288
+ Style/OperatorMethodCall: # new in 1.37
289
+ Enabled: true
290
+ Style/RedundantEach: # new in 1.38
291
+ Enabled: true
292
+ Style/RedundantInitialize: # new in 1.27
293
+ Enabled: true
294
+ Style/RedundantSelfAssignmentBranch: # new in 1.19
295
+ Enabled: true
296
+ Style/RedundantStringEscape: # new in 1.37
297
+ Enabled: true
298
+ Style/SelectByRegexp: # new in 1.22
299
+ Enabled: true
300
+
301
+ # ============================== Security ==============================
302
+ Security/CompoundHash: # new in 1.28
303
+ Enabled: true
304
+ Security/IoMethods: # new in 1.22
305
+ Enabled: true
306
+
307
+ # ============================== Lint ==============================
308
+ Lint/DuplicateMethods:
309
+ Enabled: false
310
+ Lint/AmbiguousOperator:
311
+ Enabled: false
312
+ Lint/DeprecatedOpenSSLConstant:
313
+ Enabled: true
314
+ Lint/MixedRegexpCaptureTypes:
315
+ Enabled: true
316
+ Lint/RaiseException:
317
+ Enabled: true
318
+ Lint/StructNewOverride:
319
+ Enabled: true
320
+ Lint/DuplicateElsifCondition:
321
+ Enabled: true
322
+ Lint/BinaryOperatorWithIdenticalOperands:
323
+ Enabled: true
324
+ Lint/DuplicateRescueException:
325
+ Enabled: true
326
+ Lint/EmptyConditionalBody:
327
+ Enabled: true
328
+ Lint/FloatComparison:
329
+ Enabled: true
330
+ Lint/MissingSuper:
331
+ Enabled: false
332
+ Lint/OutOfRangeRegexpRef:
333
+ Enabled: true
334
+ Lint/SelfAssignment:
335
+ Enabled: true
336
+ Lint/TopLevelReturnWithArgument:
337
+ Enabled: true
338
+ Lint/UnreachableLoop:
339
+ Enabled: true
340
+ Layout/BeginEndAlignment:
341
+ Enabled: true
342
+ Lint/ConstantDefinitionInBlock:
343
+ Enabled: true
344
+ Lint/DuplicateRequire:
345
+ Enabled: true
346
+ Lint/EmptyFile:
347
+ Enabled: true
348
+ Lint/HashCompareByIdentity:
349
+ Enabled: true
350
+ Lint/IdentityComparison:
351
+ Enabled: true
352
+ Lint/RedundantSafeNavigation:
353
+ Enabled: true
354
+ Lint/TrailingCommaInAttributeDeclaration:
355
+ Enabled: true
356
+ Lint/UselessMethodDefinition:
357
+ Enabled: true
358
+ Lint/UselessTimes:
359
+ Enabled: true
360
+ Lint/DuplicateBranch:
361
+ Enabled: true
362
+ Lint/DuplicateRegexpCharacterClassElement:
363
+ Enabled: true
364
+ Lint/EmptyBlock:
365
+ Enabled: true
366
+ Lint/EmptyClass:
367
+ Enabled: true
368
+ Lint/NoReturnInBeginEndBlocks:
369
+ Enabled: true
370
+ Lint/ToEnumArguments:
371
+ Enabled: true
372
+ Lint/UnmodifiedReduceAccumulator:
373
+ Enabled: true
374
+ Lint/UnexpectedBlockArity:
375
+ Enabled: true
376
+ Lint/DeprecatedConstants:
377
+ Enabled: true
378
+ Lint/LambdaWithoutLiteralBlock:
379
+ Enabled: true
380
+ Lint/NumberedParameterAssignment:
381
+ Enabled: true
382
+ Lint/OrAssignmentToConstant:
383
+ Enabled: true
384
+ Lint/RedundantDirGlobSort:
385
+ Enabled: true
386
+ Lint/SymbolConversion:
387
+ Enabled: true
388
+ Lint/TripleQuotes:
389
+ Enabled: true
390
+ Lint/AmbiguousAssignment:
391
+ Enabled: true
392
+ Lint/EmptyInPattern:
393
+ Enabled: true
394
+ Lint/AmbiguousOperatorPrecedence: # new in 1.21
395
+ Enabled: true
396
+ Lint/AmbiguousRange: # new in 1.19
397
+ Enabled: true
398
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
399
+ Enabled: true
400
+ Lint/DuplicateMagicComment: # new in 1.37
401
+ Enabled: true
402
+ Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
403
+ Enabled: true
404
+ Lint/NonAtomicFileOperation: # new in 1.31
405
+ Enabled: true
406
+ Lint/RefinementImportMethods: # new in 1.27
407
+ Enabled: true
408
+ Lint/RequireRangeParentheses: # new in 1.32
409
+ Enabled: true
410
+ Lint/RequireRelativeSelfPath: # new in 1.22
411
+ Enabled: true
412
+ Lint/UselessRuby2Keywords: # new in 1.23
413
+ Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 0.2.0
2
+ * [ISSUE](https://github.com/shlima/translate_enum/issues/9) Added pluralization
3
+
1
4
  ## 0.1.3
2
5
  * add licence file
3
6
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  # Specify your gem's dependencies in translate_enum.gemspec
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
- [![Build Status](https://semaphoreci.com/api/v1/shlima/translate_enum/branches/master/shields_badge.svg)](https://semaphoreci.com/shlima/translate_enum)
1
+ ![CI](https://github.com/shlima/translate_enum/workflows/CI/badge.svg)
2
2
  [![Code Climate](https://codeclimate.com/github/shlima/translate_enum/badges/gpa.svg)](https://codeclimate.com/github/shlima/translate_enum)
3
+ [![gem version](https://badge.fury.io/rb/health_bit.svg)](https://rubygems.org/gems/translate_enum)
3
4
 
4
5
  # TranslateEnum
5
6
 
@@ -50,6 +51,11 @@ Post.translated_statuses => [["Was published", :published, 0], ["Was archived",
50
51
 
51
52
  @post = Post.new(status: :published)
52
53
  @post.translated_status #=> "Was published"
54
+
55
+ # Each `translated` method supports
56
+ # I18n.translate attributes:
57
+
58
+ Post.translated_status(:published, raise: true, throw: true, locale: :en, count: 10)
53
59
  ```
54
60
 
55
61
  ### Use in a Form
@@ -98,3 +104,95 @@ class User < ActiveRecord::Base
98
104
  end
99
105
  end
100
106
  ```
107
+ # How To?
108
+ ## How to use pluralization
109
+ ```yaml
110
+ en:
111
+ activerecord:
112
+ attributes:
113
+ person:
114
+ gender_list:
115
+ male:
116
+ zero: No males
117
+ one: One male
118
+ other: %{count} males
119
+
120
+ ```
121
+
122
+ ```ruby
123
+ Person.translated_gender(:make, count: 0) #=> "No males"
124
+ Person.translated_genders => [["One male", :male, 0]] # and others
125
+ Person.translated_genders(count: 0) => [["No males", :male, 0]] # and others
126
+
127
+ @person = Person.new(gender: :male)
128
+ @person.translated_gender #=> "One male"
129
+ @person.translated_gender(count: 10) #=> "10 Males"
130
+ ```
131
+
132
+ ## How use translate enum in serializer
133
+
134
+ Example for Grape:
135
+
136
+ ```ruby
137
+ class Feedback < ApplicationRecord
138
+ include TranslateEnum
139
+
140
+ enum topic: {
141
+ question: 'question', issue: 'issue', complaint: 'complaint', offer: 'offer',
142
+ investment: 'investment'
143
+ }
144
+
145
+ translate_enum :topic
146
+ end
147
+ ```
148
+
149
+ ```ruby
150
+ class FeedbacksApi < Grape::API
151
+ resource :feedbacks do
152
+ get 'enums' do
153
+ present Feedback.method(:translated_topics), with: TranslateEnumSerializer
154
+ end
155
+ end
156
+ end
157
+ ```
158
+
159
+ ```ruby
160
+ class TranslateEnumSerializer < Grape::Entity
161
+ expose :enum, as: ->(method) { method.name[/translated_(.*)/, 1] } do |method|
162
+ method.call.map do |translation, key, _value|
163
+ { value: key, translation: translation }
164
+ end
165
+ end
166
+ end
167
+ ```
168
+
169
+ ```bash
170
+ curl http://localhost:3000/feedbacks/enums
171
+ ```
172
+
173
+ ```json
174
+ {
175
+ "topics": [
176
+ {
177
+ "value": "question",
178
+ "translation": "Vopros"
179
+ },
180
+ {
181
+ "value": "issue",
182
+ "translation": "Problema"
183
+ },
184
+ {
185
+ "value": "complaint",
186
+ "translation": "Zhaloba"
187
+ },
188
+ {
189
+ "value": "offer",
190
+ "translation": "Predlozhenie"
191
+ },
192
+ {
193
+ "value": "investment",
194
+ "translation": "Invisticii"
195
+ }
196
+ ]
197
+ }
198
+ ```
data/Rakefile CHANGED
@@ -1,2 +1,4 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ task default: :spec
data/bin/release.sh ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+
3
+ rm ./*.gem
4
+ gem build translate_enum.gemspec
5
+ gem push translate_enum-*
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  # Require this fle in order to be +TranslateEnum+ included in +ActiveRecord::Base+
2
3
  # @example
3
4
  # require 'translate_enum/active_record'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TranslateEnum
2
4
  class Builder
3
5
  attr_accessor :i18n_scope
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module TranslateEnum
2
- VERSION = '0.1.3'
4
+ VERSION = '0.2.0'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/concern'
2
4
  require 'active_support/core_ext/string'
3
5
  require 'translate_enum/version'
@@ -20,25 +22,29 @@ module TranslateEnum
20
22
  builder = Builder.new(self, attribute, &block)
21
23
 
22
24
  # User.translated_status(:active)
23
- define_singleton_method(builder.method_name_singular) do |key|
24
- I18n.translate("#{builder.i18n_scope}.#{builder.i18n_location(key)}", default: builder.i18n_default_location(key))
25
+ define_singleton_method(builder.method_name_singular) do |key, throw: false, raise: false, locale: nil, **options|
26
+ opts = { default: builder.i18n_default_location(key) }.merge(options)
27
+ I18n.translate("#{builder.i18n_scope}.#{builder.i18n_location(key)}", throw: throw, raise: raise, locale: locale, **opts)
25
28
  end
26
29
 
27
30
  # @return [Array]
28
31
  # @example
29
32
  # f.select_field :gender, f.object.class.translated_genders
30
- define_singleton_method(builder.method_name_plural) do
33
+ define_singleton_method(builder.method_name_plural) do |throw: false, raise: false, locale: nil, **options|
34
+ options = { count: 1 }.merge(options)
31
35
  public_send(builder.enum_klass_method_name).map do |key, value|
32
- [public_send(builder.method_name_singular, key), key, value]
36
+ translation = public_send(builder.method_name_singular, key, throw: throw, raise: raise, locale: locale, **options)
37
+ [translation, key, value]
33
38
  end
34
39
  end
35
40
 
36
41
  # @return [String]
37
42
  # @example
38
43
  # @user.translated_gender
39
- define_method(builder.method_name_singular) do
44
+ define_method(builder.method_name_singular) do |throw: false, raise: false, locale: nil, **options|
40
45
  if (key = public_send(builder.enum_instance_method_name)).present?
41
- self.class.public_send(builder.method_name_singular, key)
46
+ options = { count: 1 }.merge(options)
47
+ self.class.public_send(builder.method_name_singular, key, throw: throw, raise: raise, locale: locale, **options)
42
48
  end
43
49
  end
44
50
  end
@@ -1,6 +1,6 @@
1
- lib = File.expand_path('../lib', __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'translate_enum/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/translate_enum/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'translate_enum'
@@ -11,20 +11,24 @@ Gem::Specification.new do |spec|
11
11
  spec.description = 'Simple, zero-dependant enum translation gem for Rails'
12
12
  spec.homepage = 'https://github.com/shlima/translate_enum'
13
13
  spec.license = 'MIT'
14
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.6.0')
15
+ spec.metadata['rubygems_mfa_required'] = 'true'
14
16
 
15
- spec.files = `git ls-files -z`.split("\x0").reject do |f|
16
- f.match(%r{^(test|spec|features)/})
17
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
18
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
19
  end
18
20
 
19
21
  spec.bindir = 'exe'
20
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ['lib']
23
+ spec.require_paths = %w[lib]
22
24
 
23
25
  spec.add_dependency 'activesupport'
24
- spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'actionview'
27
+ spec.add_development_dependency 'activemodel'
25
28
  spec.add_development_dependency 'bundler'
29
+ spec.add_development_dependency 'pry'
26
30
  spec.add_development_dependency 'rake'
27
31
  spec.add_development_dependency 'rspec'
28
- spec.add_development_dependency 'activemodel'
29
- spec.add_development_dependency 'actionview'
32
+ spec.add_development_dependency 'rubocop'
33
+ spec.add_development_dependency 'rubocop-performance'
30
34
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translate_enum
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksandr Shylau
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2022-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -25,7 +25,21 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: pry
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activemodel
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -52,6 +66,20 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -81,7 +109,7 @@ dependencies:
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
- name: activemodel
112
+ name: rubocop
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
115
  - - ">="
@@ -95,7 +123,7 @@ dependencies:
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
- name: actionview
126
+ name: rubocop-performance
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - ">="
@@ -115,14 +143,17 @@ executables: []
115
143
  extensions: []
116
144
  extra_rdoc_files: []
117
145
  files:
146
+ - ".github/workflows/main.yml"
118
147
  - ".gitignore"
119
148
  - ".rspec"
149
+ - ".rubocop.yml"
120
150
  - CHANGELOG.md
121
151
  - Gemfile
122
152
  - MIT-LICENSE
123
153
  - README.md
124
154
  - Rakefile
125
155
  - bin/console
156
+ - bin/release.sh
126
157
  - bin/setup
127
158
  - lib/translate_enum.rb
128
159
  - lib/translate_enum/active_record.rb
@@ -132,8 +163,9 @@ files:
132
163
  homepage: https://github.com/shlima/translate_enum
133
164
  licenses:
134
165
  - MIT
135
- metadata: {}
136
- post_install_message:
166
+ metadata:
167
+ rubygems_mfa_required: 'true'
168
+ post_install_message:
137
169
  rdoc_options: []
138
170
  require_paths:
139
171
  - lib
@@ -141,16 +173,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
173
  requirements:
142
174
  - - ">="
143
175
  - !ruby/object:Gem::Version
144
- version: '0'
176
+ version: 2.6.0
145
177
  required_rubygems_version: !ruby/object:Gem::Requirement
146
178
  requirements:
147
179
  - - ">="
148
180
  - !ruby/object:Gem::Version
149
181
  version: '0'
150
182
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 3.0.0.beta1
153
- signing_key:
183
+ rubygems_version: 3.3.7
184
+ signing_key:
154
185
  specification_version: 4
155
186
  summary: Rails translate enum
156
187
  test_files: []