copy_tuner_client 2.1.2 → 2.2.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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +5 -0
  3. data/.rubocop.yml +46 -1
  4. data/CHANGELOG.md +2 -235
  5. data/CLAUDE.md +1 -0
  6. data/Gemfile +1 -0
  7. data/README.md +42 -5
  8. data/copy_tuner_client.gemspec +3 -3
  9. data/gemfiles/8.0.gemfile +3 -3
  10. data/gemfiles/8.1.gemfile +3 -3
  11. data/gemfiles/main.gemfile +3 -3
  12. data/lib/copy_tuner_client/cache.rb +34 -27
  13. data/lib/copy_tuner_client/client.rb +35 -23
  14. data/lib/copy_tuner_client/configuration.rb +87 -40
  15. data/lib/copy_tuner_client/copyray/rewriter.rb +1 -1
  16. data/lib/copy_tuner_client/copyray.rb +1 -0
  17. data/lib/copy_tuner_client/copyray_middleware.rb +31 -24
  18. data/lib/copy_tuner_client/dotted_hash.rb +7 -7
  19. data/lib/copy_tuner_client/engine.rb +4 -6
  20. data/lib/copy_tuner_client/helper_extension.rb +58 -54
  21. data/lib/copy_tuner_client/i18n_backend.rb +12 -14
  22. data/lib/copy_tuner_client/i18n_compat.rb +2 -1
  23. data/lib/copy_tuner_client/poller.rb +3 -4
  24. data/lib/copy_tuner_client/prefixed_logger.rb +13 -12
  25. data/lib/copy_tuner_client/process_guard.rb +29 -26
  26. data/lib/copy_tuner_client/queue_with_timeout.rb +29 -19
  27. data/lib/copy_tuner_client/rails.rb +9 -8
  28. data/lib/copy_tuner_client/request_sync.rb +26 -24
  29. data/lib/copy_tuner_client/simple_form_extention.rb +10 -6
  30. data/lib/copy_tuner_client/translation_log.rb +10 -5
  31. data/lib/copy_tuner_client/version.rb +1 -1
  32. data/lib/copy_tuner_client.rb +4 -8
  33. data/lib/tasks/copy_tuner_client_tasks.rake +14 -16
  34. data/skills/copy-tuner-to-locales-cleanup/SKILL.md +5 -5
  35. data/skills/copy-tuner-to-locales-migrate-prefix/SKILL.md +69 -37
  36. data/skills/copy-tuner-to-locales-migrate-prefix/references/example-touchpoints.md +31 -10
  37. data/skills/copy-tuner-to-locales-migrate-prefix/scripts/migrate_prefix.rb +158 -13
  38. data/skills/copy-tuner-to-t-migrate/scripts/migrate_tt.rb +19 -17
  39. data/spec/copy_tuner_client/cache_spec.rb +63 -57
  40. data/spec/copy_tuner_client/client_spec.rb +82 -81
  41. data/spec/copy_tuner_client/configuration_spec.rb +380 -206
  42. data/spec/copy_tuner_client/copyray/marker_spec.rb +2 -1
  43. data/spec/copy_tuner_client/copyray/rewriter_spec.rb +15 -10
  44. data/spec/copy_tuner_client/copyray_middleware_spec.rb +9 -6
  45. data/spec/copy_tuner_client/copyray_spec.rb +8 -8
  46. data/spec/copy_tuner_client/dotted_hash_spec.rb +33 -33
  47. data/spec/copy_tuner_client/helper_extension_spec.rb +47 -44
  48. data/spec/copy_tuner_client/i18n_backend_spec.rb +144 -143
  49. data/spec/copy_tuner_client/poller_spec.rb +25 -24
  50. data/spec/copy_tuner_client/prefixed_logger_spec.rb +15 -12
  51. data/spec/copy_tuner_client/process_guard_spec.rb +27 -27
  52. data/spec/copy_tuner_client/request_sync_spec.rb +51 -58
  53. data/spec/copy_tuner_client/translation_log_spec.rb +38 -24
  54. data/spec/copy_tuner_client/warden_integration_spec.rb +95 -0
  55. data/spec/copy_tuner_client_spec.rb +5 -6
  56. data/spec/support/client_spec_helpers.rb +1 -1
  57. data/spec/support/defines_constants.rb +3 -34
  58. data/spec/support/fake_client.rb +1 -3
  59. data/spec/support/fake_copy_tuner_app.rb +54 -62
  60. data/spec/support/fake_html_safe_string.rb +2 -3
  61. data/spec/support/fake_logger.rb +22 -21
  62. data/spec/support/fake_passenger.rb +4 -6
  63. data/spec/support/fake_unicorn.rb +2 -4
  64. data/spec/support/middleware_stack.rb +38 -4
  65. data/spec/support/writing_cache.rb +4 -4
  66. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 34fcab16da8e238f416a8d4be1c68212818ae95afb7f82112391517e901fbb8f
4
- data.tar.gz: dc9a727af71a83e39cb4d4c4aa41a8d1e982244936f294462da8e44b0b57d9fc
3
+ metadata.gz: 6a9a2fe07a403679fa3bf6d10c72c13fadcd31536af653a79b3e6d84e80c10ab
4
+ data.tar.gz: b3300594e38799ec7004f4c4fb0e35b051a447c6dd8b66ffb512bb59d7b851b2
5
5
  SHA512:
6
- metadata.gz: aed1f966e3c35e5d25f82fc96c56ff5532dd0b8d651be0a275f7f6f85f10a0bc58efe6b414ef004140306be70c2c2294c8c1054a112530a32e21070b098f4557
7
- data.tar.gz: 9179c177ecbc48104ea0b17db2e6adc1f88e8aa4a5dac4eb0366e171543d2f83bc03e160d7f6cadf65ccb4e8664280904b0c06eca2260d222c9463a51449ff04
6
+ metadata.gz: 5af9d06699d0361e360ea31dd4bb67ba04d2e711e0324ee9d85ee59914404ef905e173e7b6fd6ef81ede67773784fd4788ccb45fac7399ce57ad1b67d6d094ce
7
+ data.tar.gz: 2143f94b230219cae83f8d317f52ba338b282894178edce8129eac5382be76836209fbb29b8dd9e25ac96d3a91a6b93fa326fed4c426f9b2304b9b12d9233482
data/.gitignore CHANGED
@@ -22,3 +22,8 @@ node_modules
22
22
 
23
23
  Gemfile.lock
24
24
  .claude/settings.local.json
25
+
26
+ # >>> bundler-skills managed >>>
27
+ .claude/skills/gem-*
28
+ .agents/skills/gem-*
29
+ # <<< bundler-skills managed <<<
data/.rubocop.yml CHANGED
@@ -1,7 +1,52 @@
1
1
  inherit_gem:
2
- sgcop: ruby/rubocop.yml
2
+ sgcop:
3
+ - ruby/rubocop_strict.yml
4
+ - ruby/rubocop_rspec_strict.yml
5
+
6
+ plugins:
7
+ - rubocop-rake
8
+ - rubocop-rspec
3
9
 
4
10
  # .ruby-version が RuboCop 未対応の新しい Ruby を指すと解析が落ちるため、
5
11
  # サポート最低バージョンを明示する
12
+ # rubocop-rails は Rails プロジェクトではないため意図的に読み込まない
6
13
  AllCops:
7
14
  TargetRubyVersion: 3.3
15
+ NewCops: enable
16
+ SuggestExtensions: false
17
+
18
+ # gemfiles/*.gemfile が `gemspec path: '../'` で本体 gemspec の development dependency を
19
+ # 読み込む構成のため、Gemfile 側への移行は各 gemfiles/*.gemfile への書き戻しが必要になり
20
+ # 意味を変えない自動修正の範囲を超える。gemspec でのdevelopment dependency 宣言を維持する。
21
+ Gemspec/DevelopmentDependencies:
22
+ Exclude:
23
+ - 'copy_tuner_client.gemspec'
24
+
25
+ # middleware(テスト対象自身)の private メソッド append_js / helpers を no-op や
26
+ # フェイクに差し替えないと、Rails の ActionController::Base.helpers 依存を外して
27
+ # Rewriter の効果だけを検証できないため対象外。
28
+ RSpec/SubjectStub:
29
+ Exclude:
30
+ - 'spec/copy_tuner_client/copyray_middleware_spec.rb'
31
+
32
+ # Ruby 標準 Queue#pop(non_block=false) のインターフェースに意図的に合わせた実装のため、
33
+ # キーワード引数化すると標準 Queue との互換性が崩れる。
34
+ Style/OptionalBooleanParameter:
35
+ Exclude:
36
+ - 'lib/copy_tuner_client/queue_with_timeout.rb'
37
+
38
+ # Client#download は yield 前提の実装で、ブロックを渡さないと downloaded 時に
39
+ # LocalJumpError になる。ダウンロード結果自体を検証しないテストでは空ブロックが必須。
40
+ Lint/EmptyBlock:
41
+ Exclude:
42
+ - 'spec/copy_tuner_client/client_spec.rb'
43
+
44
+ # 要判断: configuration_spec.rb の i18n/config/application は Rails gem 自体を
45
+ # stub_const('Rails', Module.new) で丸ごと偽装するための double。ActiveSupport::OrderedOptions
46
+ # は method_missing 経由でアクセサを実装するため instance_double では検証できない。
47
+ # request_sync_spec.rb の app は Rack app プロトコル(call(env) を実装する任意オブジェクト)で
48
+ # 対応する具体的なクラスが存在しないため、Duck Typing 前提の double が妥当。
49
+ RSpec/VerifiedDoubles:
50
+ Exclude:
51
+ - 'spec/copy_tuner_client/configuration_spec.rb'
52
+ - 'spec/copy_tuner_client/request_sync_spec.rb'
data/CHANGELOG.md CHANGED
@@ -1,235 +1,2 @@
1
- ## Unreleased
2
-
3
- - **【後方互換性に影響】** `config.exclude_key_regexp` を削除しました。後継の `config.local_first_key_regexp`
4
- を使ってください。両者は対象キーの形式が異なります(`exclude_key_regexp` は locale 付き `ja.views.foo`、
5
- `local_first_key_regexp` は locale を除いた `views.foo`)。正規表現から locale プレフィックスを外して
6
- 移行してください。挙動も異なり、`local_first_key_regexp` は lookup 時に CopyTuner キャッシュをスキップして
7
- ローカル YAML を優先します(完全分離)。
8
- - **【後方互換性に影響】** `config.project_id` を必須にしました。未設定のまま `configure`(`apply`)すると
9
- `ArgumentError: project_id is required` で失敗します。これまで `project_id` 未設定時は `api_key` へ
10
- フォールバックして deprecation 警告を出していましたが、このフォールバックは削除しました。initializer に
11
- `config.project_id = <プロジェクト ID>` を設定してください。
12
- - Copyray オーバーレイのマーカー方式を刷新。訳文への HTML コメント `<!--COPYRAY key-->` 注入をやめ、
13
- 可視トークン `⟦CT:key⟧` を埋め込んだうえで `CopyrayMiddleware` が `data-copyray-key` 属性に変換し、
14
- トークンを HTML から完全に除去するようになりました。最終配信 HTML にコメント・トークンは残りません。
15
- - **【後方互換性に影響】** `config.html_escape` 設定を削除しました。HTML の安全性判定は i18n 標準
16
- (`.html` / `_html` で終わるキーのみ html_safe)に統一され、この設定は参照されなくなっていました(no-op)。
17
- no-op だったため動作には影響しませんが、`config.html_escape = ...` を設定している initializer は
18
- `NoMethodError` になるため、その行を削除してください。`html_escape = false`(全訳文を html_safe 扱いに
19
- する旧互換挙動)に依存していたアプリは、`.html` / `_html` キー命名へ移行してください。
20
- - Copyray オーバーレイは平文・html_safe(`.html` / `_html` キー)どちらの訳文もハイライト対象です。マーカートークンの
21
- 区切り記号は HTML 特殊文字ではないため、平文訳文が ActionView でエスケープされてもトークンは無傷で残り、
22
- `data-copyray-key` 属性へ正しく変換されます。`<head>` 内(title/meta)はトークンを除去するのみでオーバーレイ
23
- 非対象ですが、従来どおりリスト導線(CopyTuner バー)から編集できます。
24
- - **【後方互換性に影響】** `tt` ヘルパーを削除しました。マーカー方式の刷新で `t`(`translate`)が安全にマーカー
25
- 注入できるようになり、`tt` の存在理由は失われました。`tt` の呼び出しは `t` へ置き換えてください。`tt` を使い続けたい
26
- アプリは、ビューヘルパーで `t` に委譲するだけの `tt` を自前で定義してください(gem 撤去後は `t` と実質同義)。
27
-
28
- ## 0.16.1
29
-
30
- - Support for i18n@1.13.0
31
- - キーの相対パス指定とdefaultオプションを組み合わせた場合の不具合修正
32
-
33
- ## 0.16.0
34
-
35
- - Railsエンジン内のviewではオリジナルのtヘルパが呼ばれるように修正
36
-
37
- ## 0.15.1
38
-
39
- - tヘルパーにdefault引数が渡された場合に初期値として登録されない問題を修正
40
-
41
- ## 0.15.0
42
-
43
- - Drop support for ruby 2.7
44
-
45
- ## 0.14.1
46
-
47
- - Fix super call in define_method
48
-
49
- ## 0.14.0
50
-
51
- - Add Support for good_job
52
- - Drop Support for Resque
53
-
54
- ## 0.13.5
55
-
56
- - Rename assets
57
-
58
- ## 0.13.4
59
-
60
- - Fix csp nonce
61
-
62
- ## 0.13.3
63
-
64
- - Add `media="all"` attribute to stylesheet link tag
65
-
66
- ## 0.13.2
67
-
68
- - Add `crossorigin="anonymous"` attribute to script tag
69
-
70
- ## 0.13.1
71
-
72
- - Add `type="module"` attribute to script tag
73
-
74
- ## 0.13.0
75
-
76
- - Drop support for ruby 2.6
77
-
78
- ## 0.12.0
79
-
80
- - Add `config.ignored_keys` and `config.ignored_key_handler`
81
-
82
- ## 0.11.0
83
-
84
- - Remove deprecated rescue_format option
85
- - Fix ruby@2.7 keyword warning
86
-
87
- ## 0.10.0
88
-
89
- - Add copy_tuner:detect_html_incompatible_keys task
90
-
91
- ## 0.9.0
92
-
93
- - Do not upload invalid type keys
94
-
95
- ## 0.8.1
96
-
97
- - Fix bug in `CopyrayMiddleware`
98
-
99
- ## 0.8.0
100
-
101
- - Change the default value of config.upload_disabled_environments
102
-
103
- ## 0.7.0
104
-
105
- - Add config.upload_disabled_environments
106
-
107
- ## 0.6.2
108
-
109
- - Add arguments to export task
110
-
111
- ## 0.6.1
112
-
113
- - Fix ruby@2.7 keyword warning
114
-
115
- ## 0.6.0
116
-
117
- - Drop support for ruby 2.4
118
- - Drop support for rails 5.1
119
-
120
- ## 0.5.2
121
-
122
- - Do not upload invalid keys
123
-
124
- ## 0.5.1
125
-
126
- - Do not upload downloaded keys
127
-
128
- ## 0.5.0
129
-
130
- - Drop support for ruby 2.3
131
- - Add tt helper
132
- - Add copy_tuner:detect_conflict_keys task
133
- - Do not re-upload empty keys
134
- - Fix dual loading tasks
135
- - Remove config.copyray_js_injection_regexp_for_debug
136
- - Remove config.copyray_js_injection_regexp_for_precompiled
137
- - Download translation when initialization
138
-
139
- ## 0.4.11
140
-
141
- - changes
142
- - Fix hide toggle button on mobile device.
143
-
144
- ## 0.4.10
145
-
146
- - changes
147
- - Hide copyray bar on all media.
148
-
149
- ## 0.4.9
150
-
151
- - changes
152
- - Smaller toggle button.
153
- - Hide toggle button on mobile device.
154
-
155
- ## 0.4.8
156
-
157
- - changes
158
- - Support passenger 5.3.x
159
-
160
- ## 0.4.7
161
-
162
- - changes
163
- - Compatibile with bullet gem (rewrap response with ActionDispatch::Response::RackBody)
164
-
165
- ## 0.4.6
166
-
167
- - changes
168
- - Performance imporovement (sync with server asynchronously)
169
- - Add config.middleware_position
170
-
171
- ## 0.4.5
172
-
173
- - changes
174
- - Fix deprecated css.
175
-
176
- ## 0.4.4
177
-
178
- - bug fix
179
- - Don't upload resolved default values.
180
-
181
- ## 0.4.3
182
-
183
- - bug fix
184
- - Start poller thread regardless of puma mode. #39
185
-
186
- ## 0.4.2
187
-
188
- - changes
189
- - span tag is no longer added to translation text.
190
-
191
- ## 0.4.1
192
-
193
- - bug fixes
194
-
195
- - js injection failed if jquery is not used. #33
196
- - Fix some js error. #34
197
- - Wrong key is displayed if scoped option is used. #35
198
-
199
- - deprecation
200
- - config.copyray_js_injection_regexp_for_debug is no longer needed.
201
- - config.copyray_js_injection_regexp_for_precompiled is no longer needed.
202
-
203
- ## 0.4.0
204
-
205
- - Remove jQuery dependency.
206
-
207
- ## 0.3.5
208
-
209
- - Support Rails 5.1
210
-
211
- ## 0.3.4
212
-
213
- - Use Logger to /dev/null as default when rails console
214
-
215
- ## 0.3.3
216
-
217
- - Add config.locales. (#24)
218
- - Fix initialization order bug. (#25)
219
-
220
- ## 0.3.2
221
-
222
- - Support I18n.t :scope option.
223
- - Update copyray_js_injection_regexp_for_debug.
224
-
225
- ## 0.3.1
226
-
227
- - Add search box to copyray bar.
228
- - Add disable_copyray_comment_injection to configuration.
229
-
230
- ## 0.3.0
231
-
232
- - Use https as default.
233
- - Download blurbs from S3.
234
- - Add toolbar.
235
- - "Translations in this page" menu.
1
+ > [!NOTE]
2
+ > 変更履歴は [GitHub Releases](https://github.com/SonicGarden/copy-tuner-ruby-client/releases) に移行済みです。
data/CLAUDE.md CHANGED
@@ -26,6 +26,7 @@ Rails 統合は engine.rb のイニシャライザ経由(ヘルパー/SimpleFo
26
26
  - 新機能・バグ修正ともに「テスト追加 → RED 確認 → 実装 → GREEN」のサイクルを守る
27
27
  - テストを書かずに実装を先行させない
28
28
  - **コメントは WHY のみ日本語で書く**: 識別子やコードから読み取れる WHAT は書かない
29
+ (例外: RuboCop Style/Documentation 対応でクラス/モジュール直前に追加する一行の説明コメントは、名前だけでは把握しづらいクラスの役割を一目で示す目的のため、WHAT の説明も可)
29
30
  - **テストの `describe` / `context` / `it` の説明文は日本語で書く**: 識別子(クラス名・メソッド名など)はそのまま
30
31
 
31
32
  ## Gotchas
data/Gemfile CHANGED
@@ -2,4 +2,5 @@ source 'http://rubygems.org'
2
2
 
3
3
  gemspec
4
4
 
5
+ gem 'bundler-skills'
5
6
  gem 'sgcop', github: 'SonicGarden/sgcop'
data/README.md CHANGED
@@ -62,20 +62,57 @@ CopyTuner で一元管理している翻訳を、`views.*` のような単位で
62
62
 
63
63
  アプリ独自の `number.*` キー(例 `number.gift_amount`)は対象外で、従来どおり CopyTuner で管理できます。
64
64
 
65
- ## Claude Code スキル
65
+ ## Middleware の挿入位置
66
66
 
67
- `skills/copy-tuner/` Claude Code 向けのスキルが含まれています。
67
+ CopyTuner は開発環境で `RequestSync` / `CopyrayMiddleware` Rack の middleware スタックに挿入します。`RequestSync` はリクエスト毎に CopyTuner サーバと同期し、`CopyrayMiddleware` はページ内のマーカー(`⟦CT:key⟧`)を除去・変換します。
68
68
 
69
- ### copy-tuner スキル
69
+ 挿入位置は自動で決まるため、通常は設定不要です。Devise(Warden)を使っているアプリでは `Warden::Manager` の直前、それ以外の環境ではスタック末尾に挿入されます。
70
70
 
71
- i18n キーの操作を支援するスキルです。翻訳キーの検索・登録・確認などの依頼に自動的に使用されます。
71
+ Devise 併用時に Warden の直前へ寄せるのは `throw :warden` の挙動に対応するためです。`throw :warden` は `Warden::Manager` の `catch(:warden)` までスタックを巻き戻すため、CopyTuner の middleware が Warden より内側にあると、認証エラー時のレスポンス(`Devise::FailureApp` が返す HTML)を受け取れず、Copyray のマーカーがページに残ってしまいます。
72
+
73
+ 位置を変えたい場合は `config.middleware_position` に `{ before: SomeMiddleware }` または `{ after: SomeMiddleware }` を指定すると、このデフォルトを上書きできます。
74
+
75
+ ```ruby
76
+ CopyTunerClient.configure do |config|
77
+ # ...
78
+ config.middleware_position = { after: Rack::Runtime }
79
+ end
80
+ ```
81
+
82
+ 指定した middleware がスタックに存在しない場合、Rails の起動時に例外(`No such middleware to insert before: ...` / `... insert after: ...`)が発生します。
83
+
84
+ ## Claude Code スキル
85
+
86
+ `skills/` 以下に Claude Code 向けのスキルが含まれています。
72
87
 
73
88
  ```
74
- gh skill install SonicGarden/copy-tuner-ruby-client copy-tuner --scope project
89
+ gh skill install SonicGarden/copy-tuner-ruby-client <スキル名> --scope project
75
90
  ```
76
91
 
92
+ ### copy-tuner スキル
93
+
94
+ i18n キーの操作を支援するスキルです。翻訳キーの検索・登録・確認などの依頼に自動的に使用されます。
95
+
77
96
  詳細: [skills/copy-tuner/SKILL.md](skills/copy-tuner/SKILL.md)
78
97
 
98
+ ### copy-tuner-to-locales-migrate-prefix スキル
99
+
100
+ copy_tuner が集中管理する i18n キーを、prefix(正規表現)単位で `config/locales` のローカル YAML 管理へ移行するスキルです。gem は残したまま特定 prefix だけをローカル化する「部分ローカル化」と、全 prefix を移して完全撤去する「全移行」の両方に使えます。明示的に呼び出したときのみ動作します。
101
+
102
+ 詳細: [skills/copy-tuner-to-locales-migrate-prefix/SKILL.md](skills/copy-tuner-to-locales-migrate-prefix/SKILL.md)
103
+
104
+ ### copy-tuner-to-locales-cleanup スキル
105
+
106
+ `copy-tuner-to-locales-migrate-prefix` で全 prefix の移行が完了した後に、gem・初期化子・CI・deploy・ドキュメント・MCP 設定を一括撤去し、copy_tuner 依存を完全に取り除くスキルです。明示的に呼び出したときのみ動作します。
107
+
108
+ 詳細: [skills/copy-tuner-to-locales-cleanup/SKILL.md](skills/copy-tuner-to-locales-cleanup/SKILL.md)
109
+
110
+ ### copy-tuner-to-t-migrate スキル
111
+
112
+ copy_tuner_client v2.0.0 で削除された独自ヘルパー `tt` の呼び出しを、Rails 標準の `t`(`translate`)へ置換するスキルです。機械的に安全な箇所は一括変換し、文字列加工や `label` の第一引数に渡している箇所は 1 件ずつ確認しながら置換します。破壊的な一括書き換えを含むため、明示的に呼び出したときのみ動作します。
113
+
114
+ 詳細: [skills/copy-tuner-to-t-migrate/SKILL.md](skills/copy-tuner-to-t-migrate/SKILL.md)
115
+
79
116
  Development
80
117
  =================
81
118
 
@@ -21,9 +21,9 @@ Gem::Specification.new do |s|
21
21
  s.files = `git ls-files`.split("\n")
22
22
  s.homepage = 'https://github.com/SonicGarden/copy-tuner-ruby-client'
23
23
 
24
- s.metadata["homepage_uri"] = s.homepage
25
- s.metadata["source_code_uri"] = "https://github.com/SonicGarden/copy-tuner-ruby-client"
26
- s.metadata["changelog_uri"] = "https://github.com/SonicGarden/copy-tuner-ruby-client/releases"
24
+ s.metadata['homepage_uri'] = s.homepage
25
+ s.metadata['source_code_uri'] = 'https://github.com/SonicGarden/copy-tuner-ruby-client'
26
+ s.metadata['changelog_uri'] = 'https://github.com/SonicGarden/copy-tuner-ruby-client/releases'
27
27
  s.metadata['rubygems_mfa_required'] = 'true'
28
28
 
29
29
  s.name = 'copy_tuner_client'
data/gemfiles/8.0.gemfile CHANGED
@@ -1,5 +1,5 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- gem "rails", "~> 8.0"
3
+ gem 'rails', '~> 8.0'
4
4
 
5
- gemspec :path => "../"
5
+ gemspec path: '../'
data/gemfiles/8.1.gemfile CHANGED
@@ -1,5 +1,5 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- gem "rails", "~> 8.1"
3
+ gem 'rails', '~> 8.1'
4
4
 
5
- gemspec :path => "../"
5
+ gemspec path: '../'
@@ -1,5 +1,5 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
- gem "rails", github: "rails/rails", branch: "main"
3
+ gem 'rails', github: 'rails/rails', branch: 'main'
4
4
 
5
- gemspec :path => "../"
5
+ gemspec path: '../'
@@ -23,7 +23,7 @@ module CopyTunerClient
23
23
  @local_first_key_regexp = options[:local_first_key_regexp]
24
24
  @upload_disabled = options[:upload_disabled]
25
25
  @ignored_keys = options.fetch(:ignored_keys, [])
26
- @ignored_key_handler = options.fetch(:ignored_key_handler, -> (e) { raise e })
26
+ @ignored_key_handler = options.fetch(:ignored_key_handler, ->(e) { raise e })
27
27
  @locales = Array(options[:locales]).map(&:to_s)
28
28
  # mutable states
29
29
  @blurbs = {}
@@ -48,18 +48,14 @@ module CopyTunerClient
48
48
  # @param key [String] the key of the blurb to update
49
49
  # @param value [String] the new contents of the blurb
50
50
  def []=(key, value)
51
- return unless key.include?('.')
52
- return if @locales.present? && !@locales.member?(key.split('.').first)
53
- return if @upload_disabled
51
+ return if skip_upload?(key)
54
52
 
55
53
  # NOTE: config/locales以下のファイルに除外キーが残っていた場合の対応
56
54
  key_without_locale = key.split('.')[1..].join('.')
57
55
  # NOTE: local_first キー(組み込みの Rails number.*.format + ユーザー設定)は copy_tuner と完全分離するためアップロードしない
58
56
  return if local_first_key?(key_without_locale)
59
57
 
60
- if @ignored_keys.include?(key_without_locale)
61
- @ignored_key_handler.call(IgnoredKey.new("Ignored key: #{key_without_locale}"))
62
- end
58
+ handle_ignored_key(key_without_locale)
63
59
 
64
60
  lock do
65
61
  return if @blank_keys.member?(key) || @blurbs.key?(key)
@@ -100,17 +96,16 @@ module CopyTunerClient
100
96
 
101
97
  logger.info 'Waiting for first download'
102
98
 
103
- if logger.respond_to? :flush
104
- logger.flush
105
- end
99
+ logger.flush if logger.respond_to?(:flush)
106
100
 
107
- sleep 0.1 while pending?
101
+ sleep(0.1) while pending?
108
102
  end
109
103
 
110
104
  def flush
111
- res = with_queued_changes do |queued|
112
- client.upload queued
113
- end
105
+ res =
106
+ with_queued_changes do |queued|
107
+ client.upload(queued)
108
+ end
114
109
 
115
110
  @last_uploaded_at = Time.now.utc
116
111
 
@@ -122,15 +117,16 @@ module CopyTunerClient
122
117
  def download
123
118
  @status = STATUS_PENDING unless ready?
124
119
 
125
- res = client.download(cache_fallback: pending?) do |downloaded_blurbs|
126
- blank_keys = Set.new
127
- blurbs = {}
128
- downloaded_blurbs.each { |key, value| value == '' ? blank_keys << key : blurbs[key] = value }
129
- lock do
130
- @blank_keys = blank_keys
131
- @blurbs = blurbs
120
+ res =
121
+ client.download(cache_fallback: pending?) do |downloaded_blurbs|
122
+ blank_keys = Set.new
123
+ blurbs = {}
124
+ downloaded_blurbs.each { |key, value| value == '' ? blank_keys << key : blurbs[key] = value }
125
+ lock do
126
+ @blank_keys = blank_keys
127
+ @blurbs = blurbs
128
+ end
132
129
  end
133
- end
134
130
 
135
131
  @last_downloaded_at = Time.now.utc
136
132
  @status = STATUS_READY unless ready?
@@ -163,6 +159,13 @@ module CopyTunerClient
163
159
 
164
160
  attr_reader :client, :logger
165
161
 
162
+ def skip_upload?(key)
163
+ return true unless key.include?('.')
164
+ return true if @locales.present? && !@locales.member?(key.split('.').first)
165
+
166
+ @upload_disabled
167
+ end
168
+
166
169
  # NOTE: 組み込みの Rails number.*.format キーは lookup 経路(Configuration#local_first_key?)と
167
170
  # アップロード抑止経路(ここ)で同じ判定を共有する。判定本体は Configuration に集約し付け忘れの穴を防ぐ。
168
171
  def local_first_key?(key_without_locale)
@@ -171,6 +174,12 @@ module CopyTunerClient
171
174
  @local_first_key_regexp && key_without_locale.match?(@local_first_key_regexp)
172
175
  end
173
176
 
177
+ def handle_ignored_key(key_without_locale)
178
+ return unless @ignored_keys.include?(key_without_locale)
179
+
180
+ @ignored_key_handler.call(IgnoredKey.new("Ignored key: #{key_without_locale}"))
181
+ end
182
+
174
183
  def with_queued_changes
175
184
  changes_to_push = nil
176
185
 
@@ -181,9 +190,7 @@ module CopyTunerClient
181
190
  end
182
191
  end
183
192
 
184
- if changes_to_push
185
- yield nil_value_to_empty(changes_to_push)
186
- end
193
+ yield(nil_value_to_empty(changes_to_push)) if changes_to_push
187
194
  end
188
195
 
189
196
  def nil_value_to_empty(hash)
@@ -197,8 +204,8 @@ module CopyTunerClient
197
204
  hash
198
205
  end
199
206
 
200
- def lock(&block)
201
- @mutex.synchronize &block
207
+ def lock(&)
208
+ @mutex.synchronize(&)
202
209
  end
203
210
  end
204
211
  end