globalized_method 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +20 -18
- data/README.md +10 -1
- data/lib/globalized_method.rb +14 -2
- data/lib/globalized_method/version.rb +3 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a0bada013941fe3cacbe3efe4a4542878e8910659d4793911f80402c5b9bed6
|
4
|
+
data.tar.gz: b09b83a78ff8692492a44d8b55f8e5aeaed03d5f56db38a30e28a93bddb946c1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fca9764e72a3284bc124adacd268f1ef0181f81cf43ce82badf490e87899bc310d8b1d6cb1e613bf03552e213bf5b661e09ee72d6b50412ce187f320e983d564
|
7
|
+
data.tar.gz: f06688279ed58077c275152a1025f49fa502a1c89573180e2a0eecbffa768770b3b2183bfb5b8dcadb3d0d87549c36bbc032ad69f21e7398d2c4b5ca0a1d08e9
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -7,38 +7,40 @@ PATH
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
activesupport (
|
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.
|
17
|
+
concurrent-ruby (1.1.6)
|
17
18
|
diff-lcs (1.3)
|
18
|
-
i18n (1.
|
19
|
+
i18n (1.8.2)
|
19
20
|
concurrent-ruby (~> 1.0)
|
20
21
|
method_source (0.9.2)
|
21
|
-
minitest (5.
|
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 (
|
26
|
-
rspec (3.
|
27
|
-
rspec-core (~> 3.
|
28
|
-
rspec-expectations (~> 3.
|
29
|
-
rspec-mocks (~> 3.
|
30
|
-
rspec-core (3.
|
31
|
-
rspec-support (~> 3.
|
32
|
-
rspec-expectations (3.
|
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.
|
35
|
-
rspec-mocks (3.
|
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.
|
38
|
-
rspec-support (3.
|
38
|
+
rspec-support (~> 3.9.0)
|
39
|
+
rspec-support (3.9.2)
|
39
40
|
thread_safe (0.3.6)
|
40
|
-
tzinfo (1.2.
|
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
|
-
|
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'
|
data/lib/globalized_method.rb
CHANGED
@@ -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
|
-
|
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
|
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.
|
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:
|
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.
|
135
|
+
rubygems_version: 3.0.6
|
136
136
|
signing_key:
|
137
137
|
specification_version: 4
|
138
138
|
summary: ''
|