copy_tuner_client 0.15.0 → 0.16.0

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: 375dbe69369421e9f764466f5b92f63b3eacda2235ddc0a42892620ae6474342
4
- data.tar.gz: '07638a3f438bee6a23fa8fa3109cd620585821f417c15693bfcac4589ca053d0'
3
+ metadata.gz: d026c94fe7b434afec7fa13369e91ddd784ed649336de71bb5d2d0a373201e0f
4
+ data.tar.gz: f882fbc15358fb560d5ba695e138f2ca904ed3f1e4e5b29ccac1a4c3d7e9fe06
5
5
  SHA512:
6
- metadata.gz: bc8bee8ccf7f8668e3d7abb146fe568692a0e765d9fad2bc9137185d34115703a342e2bdd79a5db3a3a0a45e5fabeedd1d70cffa7fc70fc9bd5d81c28cddd3e0
7
- data.tar.gz: 15f30baf267916980605c002524e07818e66aa7dcec62173c9c907acf54e849302862b05cf245bd3cb065668b67dcf39bb0636b62a499af709d99d2c58fdada8
6
+ metadata.gz: fc0818f17179df0462efa7a739edbd1126d4b0170d550e15834980eeaf15c61197345b2a82dc2affc911d7914a82abbb5c5a70ff71b9e8d418425841f2f51bf8
7
+ data.tar.gz: ac73b7c43742c17061f318c32ff2f642d53afaa9dad02703a5e166181ac2027312a8a4f5c70626fb77923e29410c026f834db7b4ba1948fe306b6384396fc6d5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## 0.16.0
2
+
3
+ - Railsエンジン内のviewではオリジナルのtヘルパが呼ばれるように修正
4
+
5
+ ## 0.15.1
6
+
7
+ - tヘルパーにdefault引数が渡された場合に初期値として登録されない問題を修正
8
+
1
9
  ## 0.15.0
2
10
 
3
11
  - Drop support for ruby 2.7
@@ -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
- if defined?(::Rails::Railtie)
24
- require 'copy_tuner_client/engine'
25
- else
26
- CopyTunerClient::Rails.initialize
27
- end
32
+ require 'copy_tuner_client/engine'
@@ -1,6 +1,6 @@
1
1
  module CopyTunerClient
2
2
  # Client version
3
- VERSION = '0.15.0'.freeze
3
+ VERSION = '0.16.0'.freeze
4
4
 
5
5
  # API version being used to communicate with the server
6
6
  API_VERSION = '2.0'.freeze
@@ -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
- class HashArgumentView
21
- include HashArgumentHelper
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.15.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-03-29 00:00:00.000000000 Z
11
+ date: 2023-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: i18n