translateable_attributes 0.1.0 → 0.3.1

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
- SHA1:
3
- metadata.gz: 1c3f4b9d3b35070a71a8495ded176171b3de558d
4
- data.tar.gz: 434f55f169fa3b844f84d4c82106ac998664b455
2
+ SHA256:
3
+ metadata.gz: 2914565205b37db29a0b165f82c17f9f9fab874f759427bac4c4baa0d2ae4541
4
+ data.tar.gz: e7db39c5936bc5526bda12ed8746a32633f3fddff48252acc00ee7bdfdeac8ec
5
5
  SHA512:
6
- metadata.gz: 494d31020c4a2e2f7987e3c37c91018990caf3350c8c2255f06becb0485131c8eaeacda657fdd51a1db0ae88b43202a7bdfc8ddc774ebf8d682857bea68a8241
7
- data.tar.gz: 4330f27b819394806216312213dbca2a44371f654edbc0fad7de550b06622f5ba1324d886c66012f07032ddab7ebcb3c10cafef2aa23c7b67376212a5d1e232f
6
+ metadata.gz: 627685d96c6547fbe784549d033bbe0118b05b4afb0508fabb7ebc62d9203cb92a8889213022527ccb25442e12ea91b5fe23c4b3f6ba2d2b9b8e24d2ff5d3fe7
7
+ data.tar.gz: b9c06ca689ee048fb64871f7a1777be7e83a24003f428856bd2da1edef1ae57b1098a59643d9e6c4573a1dee2f594330bee374c17a1c53774249849593747b0e
data/.rubocop.yml CHANGED
@@ -6,6 +6,9 @@ AllCops:
6
6
  Metrics/LineLength:
7
7
  Max: 145
8
8
 
9
+ Metrics/BlockLength:
10
+ Max: 45
11
+
9
12
  Style/Documentation:
10
13
  Enabled: false
11
14
 
@@ -17,3 +20,18 @@ Style/ClassAndModuleChildren:
17
20
 
18
21
  Style/MethodLength:
19
22
  Enabled: false
23
+
24
+ Style/FrozenStringLiteralComment:
25
+ Enabled: false
26
+
27
+ Gemspec/RequiredRubyVersion:
28
+ Enabled: false
29
+
30
+ Style/ExpandPathArguments:
31
+ Enabled: false
32
+
33
+ Style/SymbolArray:
34
+ Enabled: false
35
+
36
+ Style/FormatStringToken:
37
+ Enabled: false
data/HISTORY.md ADDED
@@ -0,0 +1,14 @@
1
+ ### 0.3.1
2
+ Update for compatibility with I18n 1.8.9
3
+
4
+ ### 0.3.0
5
+ Allow options to be passed to I18n translation method calls
6
+
7
+ ### 0.2.1
8
+ Relax activesupport dependency
9
+
10
+ ### 0.2.0
11
+ Added `possible_attributes` class method.
12
+
13
+ ### 0.1.0
14
+ Initial release
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TranslateableAttributes ![Travis CI](https://travis-ci.org/tmikoss/translateable_attributes.svg)
2
2
 
3
- Helper methods to display translated values of object attributes (stored in database, plain object properties, ...)
3
+ Helper methods to display translated values of object attributes.
4
4
 
5
5
  ## Installation
6
6
 
@@ -29,7 +29,7 @@ en:
29
29
  completed: 'Done'
30
30
  ```
31
31
 
32
- Extend a class with `TranslateableAttributes::Methods` and call `translate_attributes` method on it, passing a hash of `attribute_name: 'translation.namespace'` to it:
32
+ Extend a class with `TranslateableAttributes::Methods` and call `translate_attributes` method on it:
33
33
 
34
34
  ```ruby
35
35
  class TranslatedClass
@@ -55,6 +55,10 @@ In addition, `attributes_for_select` class method is defined that returns all av
55
55
  TranslatedClass.states_for_select #=> [['Initiated', 'new'], ['Done', 'completed']]
56
56
  ```
57
57
 
58
+ `translate_attributes` class method accepts a hash of `attribute_name: 'translation.namespace'`. Translations are looked up by appending attribute value to provided namespace and passing that to `I18n.t` method.
59
+
60
+ For example, given `Klass.translate_attributes state: 'some.nested.translation.namespace'`, calling `Klass.translated_state 'new'` equals to `I18n.t 'some.nested.translation.namespace.new'`.
61
+
58
62
  ## Development
59
63
 
60
64
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -1,22 +1,30 @@
1
1
  module TranslateableAttributes
2
2
  module Methods
3
+ # rubocop:disable Metrics/AbcSize
3
4
  def translate_attributes(options = {})
4
5
  options.each do |attribute, namespace|
6
+ plural_attribute = attribute.to_s.pluralize
7
+
5
8
  define_method "translated_#{attribute}" do
6
9
  value = send(attribute)
7
10
  value.present? ? I18n.t("#{namespace}.#{value}", default: value) : value
8
11
  end
9
12
 
10
- define_singleton_method "#{attribute.to_s.pluralize}_for_select" do
13
+ define_singleton_method "#{plural_attribute}_for_select" do
11
14
  I18n.t(namespace).each_with_object([]) do |(value, translation), collection|
12
15
  collection << [translation, value]
13
16
  end
14
17
  end
15
18
 
16
- define_singleton_method "translated_#{attribute}" do |value|
17
- I18n.t([namespace, value].join '.')
19
+ define_singleton_method "translated_#{attribute}" do |value, translation_options = {}|
20
+ I18n.t([namespace, value].join('.'), **translation_options)
21
+ end
22
+
23
+ define_singleton_method "possible_#{plural_attribute}" do
24
+ I18n.t(namespace).keys
18
25
  end
19
26
  end
20
27
  end
28
+ # rubocop:enable Metrics/AbcSize
21
29
  end
22
30
  end
@@ -1,3 +1,3 @@
1
1
  module TranslateableAttributes
2
- VERSION = '0.1.0'
2
+ VERSION = '0.3.1'.freeze
3
3
  end
@@ -1,4 +1,3 @@
1
- # coding: utf-8
2
1
  lib = File.expand_path('../lib', __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'translateable_attributes/version'
@@ -19,7 +18,7 @@ Gem::Specification.new do |spec|
19
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
19
  spec.require_paths = ['lib']
21
20
 
22
- spec.add_runtime_dependency 'activesupport', ['>= 4', '< 5']
21
+ spec.add_runtime_dependency 'activesupport', '>= 4'
23
22
  spec.add_runtime_dependency 'i18n'
24
23
 
25
24
  spec.add_development_dependency 'bundler', '~> 1.9'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: translateable_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Toms Mikoss
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-10-07 00:00:00.000000000 Z
11
+ date: 2021-08-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -17,9 +17,6 @@ dependencies:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4'
20
- - - "<"
21
- - !ruby/object:Gem::Version
22
- version: '5'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
@@ -27,9 +24,6 @@ dependencies:
27
24
  - - ">="
28
25
  - !ruby/object:Gem::Version
29
26
  version: '4'
30
- - - "<"
31
- - !ruby/object:Gem::Version
32
- version: '5'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: i18n
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -113,6 +107,7 @@ files:
113
107
  - ".rubocop.yml"
114
108
  - ".travis.yml"
115
109
  - Gemfile
110
+ - HISTORY.md
116
111
  - LICENSE.txt
117
112
  - README.md
118
113
  - Rakefile
@@ -126,7 +121,7 @@ homepage: https://github.com/tmikoss/translateable_attributes
126
121
  licenses:
127
122
  - MIT
128
123
  metadata: {}
129
- post_install_message:
124
+ post_install_message:
130
125
  rdoc_options: []
131
126
  require_paths:
132
127
  - lib
@@ -141,9 +136,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
136
  - !ruby/object:Gem::Version
142
137
  version: '0'
143
138
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.4.5
146
- signing_key:
139
+ rubygems_version: 3.0.6
140
+ signing_key:
147
141
  specification_version: 4
148
142
  summary: Helper methods to display translated values of object attributes.
149
143
  test_files: []