globalized_method 0.1.0 → 0.1.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
2
  SHA256:
3
- metadata.gz: 555babd3c675e49387e126dc3e4d5487d9ab7859208e716f68e5cdc066b78c91
4
- data.tar.gz: 89ec8a5ea561ad6cdfe31da69757fa46f2103d0584c0f8cbb1d13b3d6c00cad6
3
+ metadata.gz: 8a0bada013941fe3cacbe3efe4a4542878e8910659d4793911f80402c5b9bed6
4
+ data.tar.gz: b09b83a78ff8692492a44d8b55f8e5aeaed03d5f56db38a30e28a93bddb946c1
5
5
  SHA512:
6
- metadata.gz: 0ea5ae7eaa201094e371f4ce27ff4e222c8c833ed2162c51738e7913c290690b3fd84e7a0edc0ce7d9e214646eaeb314412faa719a0b7384ff5d52fb9574955d
7
- data.tar.gz: 8adde5a6ba5b70676769dde172e6ae7c0e31dd92490f2fa430c37033615399d9761c1de56a2d887997e8b71e958f11df52adb0cb68c3e4260881cd43f27b1d7b
6
+ metadata.gz: fca9764e72a3284bc124adacd268f1ef0181f81cf43ce82badf490e87899bc310d8b1d6cb1e613bf03552e213bf5b661e09ee72d6b50412ce187f320e983d564
7
+ data.tar.gz: f06688279ed58077c275152a1025f49fa502a1c89573180e2a0eecbffa768770b3b2183bfb5b8dcadb3d0d87549c36bbc032ad69f21e7398d2c4b5ca0a1d08e9
data/.gitignore CHANGED
@@ -6,6 +6,7 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /*.gem
9
10
 
10
11
  # rspec failure tracking
11
12
  .rspec_status
@@ -7,38 +7,40 @@ PATH
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (5.2.2)
10
+ activesupport (6.0.2.1)
11
11
  concurrent-ruby (~> 1.0, >= 1.0.2)
12
12
  i18n (>= 0.7, < 2)
13
13
  minitest (~> 5.1)
14
14
  tzinfo (~> 1.1)
15
+ zeitwerk (~> 2.2)
15
16
  coderay (1.1.2)
16
- concurrent-ruby (1.1.4)
17
+ concurrent-ruby (1.1.6)
17
18
  diff-lcs (1.3)
18
- i18n (1.5.3)
19
+ i18n (1.8.2)
19
20
  concurrent-ruby (~> 1.0)
20
21
  method_source (0.9.2)
21
- minitest (5.11.3)
22
+ minitest (5.14.0)
22
23
  pry (0.12.2)
23
24
  coderay (~> 1.1.0)
24
25
  method_source (~> 0.9.0)
25
- rake (12.3.2)
26
- rspec (3.8.0)
27
- rspec-core (~> 3.8.0)
28
- rspec-expectations (~> 3.8.0)
29
- rspec-mocks (~> 3.8.0)
30
- rspec-core (3.8.0)
31
- rspec-support (~> 3.8.0)
32
- rspec-expectations (3.8.2)
26
+ rake (13.0.1)
27
+ rspec (3.9.0)
28
+ rspec-core (~> 3.9.0)
29
+ rspec-expectations (~> 3.9.0)
30
+ rspec-mocks (~> 3.9.0)
31
+ rspec-core (3.9.1)
32
+ rspec-support (~> 3.9.1)
33
+ rspec-expectations (3.9.0)
33
34
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.8.0)
35
- rspec-mocks (3.8.0)
35
+ rspec-support (~> 3.9.0)
36
+ rspec-mocks (3.9.1)
36
37
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.8.0)
38
- rspec-support (3.8.0)
38
+ rspec-support (~> 3.9.0)
39
+ rspec-support (3.9.2)
39
40
  thread_safe (0.3.6)
40
- tzinfo (1.2.5)
41
+ tzinfo (1.2.6)
41
42
  thread_safe (~> 0.1)
43
+ zeitwerk (2.2.2)
42
44
 
43
45
  PLATFORMS
44
46
  ruby
@@ -52,4 +54,4 @@ DEPENDENCIES
52
54
  rspec
53
55
 
54
56
  BUNDLED WITH
55
- 2.0.1
57
+ 1.17.3
data/README.md CHANGED
@@ -2,11 +2,20 @@
2
2
 
3
3
  Usage example
4
4
 
5
+ ```bash
6
+ gem install globalized_method
7
+ ```
8
+
9
+ ```ruby
10
+ # set fallbacks globally
11
+ GlobalizedMethod.fallbacks[:ru] = %i[en]
12
+ ```
13
+
5
14
  ```ruby
6
15
  class Item < ApplicationRecord # or BasicObject (works the same)
7
16
  include GlobalizedMethod
8
17
 
9
- globalized_method :name
18
+ globalized_method :name, fallbacks: { ru: %i[en] }
10
19
 
11
20
  def name_en
12
21
  'some name'
@@ -2,10 +2,18 @@
2
2
 
3
3
  require 'globalized_method/version'
4
4
  require 'active_support/concern'
5
+ require 'active_support/core_ext'
5
6
 
6
7
  module GlobalizedMethod
7
8
  extend ActiveSupport::Concern
8
9
 
10
+ # @example GlobalizedMethod.fallbacks[:uk] = %i[ru en]
11
+ def fallbacks
12
+ @fallbacks ||= {}
13
+ end
14
+
15
+ module_function :fallbacks
16
+
9
17
  class_methods do
10
18
  # # @return [Symbol] localized method name
11
19
  def global_ln(prefix)
@@ -22,10 +30,14 @@ module GlobalizedMethod
22
30
  end
23
31
  end
24
32
 
25
- def globalized_method(prefix)
33
+ # @example globalized_method :name, fallbacks: { uk: %i[ru en] }
34
+ def globalized_method(prefix, fallbacks: {})
26
35
  class_eval <<~METHODS, __FILE__, __LINE__ + 1
27
36
  def #{prefix}
28
- public_send("#{prefix}_" + I18n.locale.to_s)
37
+ public_send("#{prefix}_" + I18n.locale.to_s).presence || #{fallbacks.merge(GlobalizedMethod.fallbacks)}.fetch(I18n.locale, []).each do |locale|
38
+ result = public_send("#{prefix}_" + locale.to_s).presence
39
+ return result if result
40
+ end.presence
29
41
  end
30
42
  METHODS
31
43
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module GlobalizedMethod
4
- VERSION = '0.1.0'
3
+ module
4
+ GlobalizedMethod
5
+ VERSION = '0.1.1'
5
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: globalized_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aliaksander Shylau
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-02-20 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.0.2
135
+ rubygems_version: 3.0.6
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: ''