copy_tuner_client 0.15.0 → 0.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/copy_tuner_client/helper_extension.rb +10 -0
- data/lib/copy_tuner_client/rails.rb +10 -5
- data/lib/copy_tuner_client/version.rb +1 -1
- data/spec/copy_tuner_client/helper_extension_spec.rb +3 -17
- data/spec/copy_tuner_client/i18n_backend_spec.rb +0 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d026c94fe7b434afec7fa13369e91ddd784ed649336de71bb5d2d0a373201e0f
|
4
|
+
data.tar.gz: f882fbc15358fb560d5ba695e138f2ca904ed3f1e4e5b29ccac1a4c3d7e9fe06
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc0818f17179df0462efa7a739edbd1126d4b0170d550e15834980eeaf15c61197345b2a82dc2affc911d7914a82abbb5c5a70ff71b9e8d418425841f2f51bf8
|
7
|
+
data.tar.gz: ac73b7c43742c17061f318c32ff2f642d53afaa9dad02703a5e166181ac2027312a8a4f5c70626fb77923e29410c026f834db7b4ba1948fe306b6384396fc6d5
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,16 @@ module CopyTunerClient
|
|
5
5
|
mod.class_eval do
|
6
6
|
def translate_with_copyray_comment(key, **options)
|
7
7
|
source = translate_without_copyray_comment(key, **options)
|
8
|
+
|
9
|
+
if controller && CopyTunerClient::Rails.controller_of_rails_engine?(controller)
|
10
|
+
return source
|
11
|
+
end
|
12
|
+
|
13
|
+
# TODO: test
|
14
|
+
# NOTE: default引数が設定されている場合は、copytunerキャッシュの値をI18n.t呼び出しにより上書きしている
|
15
|
+
# SEE: https://github.com/rails/rails/blob/6c43ebc220428ce9fc9569c2e5df90a38a4fc4e4/actionview/lib/action_view/helpers/translation_helper.rb#L82
|
16
|
+
I18n.t(key, **options) if options.key?(:default)
|
17
|
+
|
8
18
|
if CopyTunerClient.configuration.disable_copyray_comment_injection
|
9
19
|
source
|
10
20
|
else
|
@@ -17,11 +17,16 @@ module CopyTunerClient
|
|
17
17
|
config.middleware = ::Rails.configuration.middleware
|
18
18
|
end
|
19
19
|
end
|
20
|
+
|
21
|
+
def self.controller_of_rails_engine?(controller)
|
22
|
+
# SEE: https://github.com/rails/rails/blob/539144d2d61770dab66c8643e744441e52538e09/activesupport/lib/active_support/core_ext/module/introspection.rb#L39-L63
|
23
|
+
engine_namespaces.include?(controller.class.module_parents[-2])
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.engine_namespaces
|
27
|
+
@engine_namespaces ||= ::Rails::Engine.subclasses.filter_map { _1.instance.railtie_namespace }
|
28
|
+
end
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
23
|
-
|
24
|
-
require 'copy_tuner_client/engine'
|
25
|
-
else
|
26
|
-
CopyTunerClient::Rails.initialize
|
27
|
-
end
|
32
|
+
require 'copy_tuner_client/engine'
|
@@ -3,36 +3,22 @@ require 'copy_tuner_client/helper_extension'
|
|
3
3
|
require 'copy_tuner_client/copyray'
|
4
4
|
|
5
5
|
describe CopyTunerClient::HelperExtension do
|
6
|
-
# rails <= 6.0.x
|
7
|
-
module HashArgumentHelper
|
8
|
-
def translate(key, options = {})
|
9
|
-
"Hello, #{options[:name]}"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
# rails >= 6.1.x
|
14
6
|
module KeywordArgumentsHelper
|
15
7
|
def translate(key, **options)
|
16
8
|
"Hello, #{options[:name]}"
|
17
9
|
end
|
18
|
-
end
|
19
10
|
|
20
|
-
|
21
|
-
|
11
|
+
def controller
|
12
|
+
nil
|
13
|
+
end
|
22
14
|
end
|
23
15
|
|
24
16
|
class KeywordArgumentsView
|
25
17
|
include KeywordArgumentsHelper
|
26
18
|
end
|
27
19
|
|
28
|
-
CopyTunerClient::HelperExtension.hook_translation_helper(HashArgumentHelper, middleware_enabled: true)
|
29
20
|
CopyTunerClient::HelperExtension.hook_translation_helper(KeywordArgumentsHelper, middleware_enabled: true)
|
30
21
|
|
31
|
-
it 'works with hash argument method' do
|
32
|
-
view = HashArgumentView.new
|
33
|
-
expect(view.translate('some.key', name: 'World')).to eq '<!--COPYRAY some.key-->Hello, World'
|
34
|
-
end
|
35
|
-
|
36
22
|
it 'works with keyword argument method' do
|
37
23
|
view = KeywordArgumentsView.new
|
38
24
|
expect(view.translate('some.key', name: 'World')).to eq '<!--COPYRAY some.key-->Hello, World'
|
@@ -39,8 +39,6 @@ describe CopyTunerClient::I18nBackend do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
it "finds available locales from locale files and cache" do
|
42
|
-
# TODO: ruby@2.7サポート終わったらこっちは不要
|
43
|
-
allow(YAML).to receive(:load_file).and_return({ 'es' => { 'key' => 'value' } })
|
44
42
|
allow(YAML).to receive(:unsafe_load_file).and_return({ 'es' => { 'key' => 'value' } })
|
45
43
|
allow(I18n).to receive(:load_path).and_return(["test.yml"])
|
46
44
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: copy_tuner_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.16.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SonicGarden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|