copy_tuner_client 0.6.1 → 0.9.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 +4 -4
- data/CHANGELOG.md +20 -0
- data/Gemfile.lock +2 -2
- data/lib/copy_tuner_client/cache.rb +2 -0
- data/lib/copy_tuner_client/configuration.rb +10 -2
- data/lib/copy_tuner_client/copyray_middleware.rb +12 -6
- data/lib/copy_tuner_client/i18n_backend.rb +4 -0
- data/lib/copy_tuner_client/translation_log.rb +1 -1
- data/lib/copy_tuner_client/version.rb +1 -1
- data/lib/tasks/copy_tuner_client_tasks.rake +4 -4
- data/spec/copy_tuner_client/i18n_backend_spec.rb +7 -0
- data/spec/copy_tuner_client/process_guard_spec.rb +2 -1
- 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: 996744608bfe0fb4a810ef7f859a0f20f8cb92c2e3646e43fa3f2f380492a0c9
|
4
|
+
data.tar.gz: e535ee0af12cf52f818077c33dfe05ff40714736dbe7a8afc454257e2ee6fc46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 76e6d0d13b2b3f311ffbfebd4cbebb98712bfd0a6d15362d8290430a26d28bda58957f54a409821ee5622c0d98eaf8219a1c26829c41a88604b2366073fbd986
|
7
|
+
data.tar.gz: b476d7b428b800767f8485fb05226c0d0c8b22b2a89396f0de8560f733c99592bd230851f94e03b5b6bf17899979f41dae84fde3248ca20f2f71e00f077fa170
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
## 0.9.0
|
2
|
+
|
3
|
+
- Do not upload invalid type keys
|
4
|
+
|
5
|
+
## 0.8.1
|
6
|
+
|
7
|
+
- Fix bug in `CopyrayMiddleware`
|
8
|
+
|
9
|
+
## 0.8.0
|
10
|
+
|
11
|
+
- Change the default value of config.upload_disabled_environments
|
12
|
+
|
13
|
+
## 0.7.0
|
14
|
+
|
15
|
+
- Add config.upload_disabled_environments
|
16
|
+
|
17
|
+
## 0.6.2
|
18
|
+
|
19
|
+
- Add arguments to export task
|
20
|
+
|
1
21
|
## 0.6.1
|
2
22
|
|
3
23
|
- Fix ruby@2.7 keyword warning
|
data/Gemfile.lock
CHANGED
@@ -14,7 +14,7 @@ GIT
|
|
14
14
|
PATH
|
15
15
|
remote: .
|
16
16
|
specs:
|
17
|
-
copy_tuner_client (0.
|
17
|
+
copy_tuner_client (0.9.0)
|
18
18
|
i18n (>= 0.5.0)
|
19
19
|
json
|
20
20
|
|
@@ -92,7 +92,7 @@ GEM
|
|
92
92
|
i18n (1.8.2)
|
93
93
|
concurrent-ruby (~> 1.0)
|
94
94
|
jaro_winkler (1.5.4)
|
95
|
-
json (2.
|
95
|
+
json (2.5.1)
|
96
96
|
loofah (2.5.0)
|
97
97
|
crass (~> 1.0.2)
|
98
98
|
nokogiri (>= 1.5.9)
|
@@ -17,6 +17,7 @@ module CopyTunerClient
|
|
17
17
|
@logger = options[:logger]
|
18
18
|
@mutex = Mutex.new
|
19
19
|
@exclude_key_regexp = options[:exclude_key_regexp]
|
20
|
+
@upload_disabled = options[:upload_disabled]
|
20
21
|
@locales = Array(options[:locales]).map(&:to_s)
|
21
22
|
# mutable states
|
22
23
|
@blurbs = {}
|
@@ -41,6 +42,7 @@ module CopyTunerClient
|
|
41
42
|
return if @exclude_key_regexp && key.match?(@exclude_key_regexp)
|
42
43
|
return unless key.include?('.')
|
43
44
|
return if @locales.present? && !@locales.member?(key.split('.').first)
|
45
|
+
return if @upload_disabled
|
44
46
|
|
45
47
|
lock do
|
46
48
|
return if @blank_keys.member?(key) || @blurbs.key?(key)
|
@@ -57,6 +57,9 @@ module CopyTunerClient
|
|
57
57
|
# @return [Array<String>] A list of environments in which the server should not be contacted
|
58
58
|
attr_accessor :test_environments
|
59
59
|
|
60
|
+
# @return [Array<String>] A list of environments in which the server should not be upload
|
61
|
+
attr_accessor :upload_disabled_environments
|
62
|
+
|
60
63
|
# @return [String] The name of the environment the application is running in
|
61
64
|
attr_accessor :environment_name
|
62
65
|
|
@@ -145,6 +148,7 @@ module CopyTunerClient
|
|
145
148
|
self.sync_interval_staging = 0
|
146
149
|
self.secure = true
|
147
150
|
self.test_environments = %w(test cucumber)
|
151
|
+
self.upload_disabled_environments = %w[production staging]
|
148
152
|
self.s3_host = 'copy-tuner-data-prod.s3.amazonaws.com'
|
149
153
|
self.disable_copyray_comment_injection = false
|
150
154
|
self.html_escape = false
|
@@ -163,7 +167,7 @@ module CopyTunerClient
|
|
163
167
|
# Returns a hash of all configurable options
|
164
168
|
# @return [Hash] configuration attributes
|
165
169
|
def to_hash
|
166
|
-
base_options = { :public
|
170
|
+
base_options = { public: public?, upload_disabled: upload_disabled? }
|
167
171
|
|
168
172
|
OPTIONS.inject(base_options) do |hash, option|
|
169
173
|
hash.merge option.to_sym => send(option)
|
@@ -198,7 +202,11 @@ module CopyTunerClient
|
|
198
202
|
# Determines if the content will fetched from the server
|
199
203
|
# @return [Boolean] Returns +true+ if in a test environment, +false+ otherwise.
|
200
204
|
def test?
|
201
|
-
test_environments.include?
|
205
|
+
test_environments.include?(environment_name)
|
206
|
+
end
|
207
|
+
|
208
|
+
def upload_disabled?
|
209
|
+
upload_disabled_environments.include?(environment_name)
|
202
210
|
end
|
203
211
|
|
204
212
|
# Determines if the configuration has been applied (internal)
|
@@ -37,14 +37,14 @@ module CopyTunerClient
|
|
37
37
|
if CopyTunerClient::TranslationLog.initialized?
|
38
38
|
json = CopyTunerClient::TranslationLog.translations.to_json
|
39
39
|
# Use block to avoid back reference \?
|
40
|
-
html
|
40
|
+
append_to_html_body(html, "<div id='copy-tuner-data' data-copy-tuner-translation-log='#{ERB::Util.html_escape json}' data-copy-tuner-url='#{CopyTunerClient.configuration.project_url}'></div>")
|
41
41
|
else
|
42
42
|
html
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
46
|
def inject_copy_tuner_bar(html)
|
47
|
-
html
|
47
|
+
append_to_html_body(html, render_copy_tuner_bar)
|
48
48
|
end
|
49
49
|
|
50
50
|
def render_copy_tuner_bar
|
@@ -59,19 +59,25 @@ module CopyTunerClient
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def append_css(html)
|
62
|
-
html
|
62
|
+
append_to_html_body(html, css_tag)
|
63
63
|
end
|
64
64
|
|
65
65
|
def append_js(html)
|
66
|
-
html.
|
67
|
-
"#{helpers.javascript_include_tag(:copyray)}\n#{Regexp.last_match}"
|
68
|
-
end
|
66
|
+
append_to_html_body(html, helpers.javascript_include_tag(:copyray))
|
69
67
|
end
|
70
68
|
|
71
69
|
def css_tag
|
72
70
|
helpers.stylesheet_link_tag :copyray, media: :all
|
73
71
|
end
|
74
72
|
|
73
|
+
def append_to_html_body(html, content)
|
74
|
+
content = content.html_safe if content.respond_to?(:html_safe)
|
75
|
+
return html unless html.include?('</body>')
|
76
|
+
|
77
|
+
position = html.rindex('</body>')
|
78
|
+
html.insert(position, content + "\n")
|
79
|
+
end
|
80
|
+
|
75
81
|
def file?(headers)
|
76
82
|
headers["Content-Transfer-Encoding"] == "binary"
|
77
83
|
end
|
@@ -61,6 +61,8 @@ module CopyTunerClient
|
|
61
61
|
private
|
62
62
|
|
63
63
|
def lookup(locale, key, scope = [], options = {})
|
64
|
+
return nil if !key.is_a?(String) && !key.is_a?(Symbol)
|
65
|
+
|
64
66
|
parts = I18n.normalize_keys(locale, key, scope, options[:separator])
|
65
67
|
key_with_locale = parts.join('.')
|
66
68
|
content = cache[key_with_locale] || super
|
@@ -86,6 +88,8 @@ module CopyTunerClient
|
|
86
88
|
|
87
89
|
def default(locale, object, subject, options = {})
|
88
90
|
content = super(locale, object, subject, options)
|
91
|
+
return content if !object.is_a?(String) && !object.is_a?(Symbol)
|
92
|
+
|
89
93
|
if content.respond_to?(:to_str)
|
90
94
|
parts = I18n.normalize_keys(locale, object, options[:scope], options[:separator])
|
91
95
|
# NOTE: ActionView::Helpers::TranslationHelper#translate wraps default String in an Array
|
@@ -19,7 +19,7 @@ module CopyTunerClient
|
|
19
19
|
def self.install_hook
|
20
20
|
I18n.class_eval do
|
21
21
|
class << self
|
22
|
-
def translate_with_copy_tuner_hook(key, **options)
|
22
|
+
def translate_with_copy_tuner_hook(key = nil, **options)
|
23
23
|
scope = options[:scope]
|
24
24
|
scope = scope.dup if scope.is_a?(Array) || scope.is_a?(String)
|
25
25
|
result = translate_without_copy_tuner_hook(key, **options)
|
@@ -6,13 +6,13 @@ namespace :copy_tuner do
|
|
6
6
|
end
|
7
7
|
|
8
8
|
desc "Export CopyTuner blurbs to yaml."
|
9
|
-
task :export => :environment do
|
9
|
+
task :export, %i[path] => :environment do |_, args|
|
10
|
+
args.with_defaults(path: "config/locales/copy_tuner.yml")
|
10
11
|
CopyTunerClient.cache.sync
|
11
12
|
|
12
13
|
if yml = CopyTunerClient.export
|
13
|
-
path
|
14
|
-
|
15
|
-
puts "Successfully exported blurbs to #{path}."
|
14
|
+
File.new("#{Rails.root}/#{args[:path]}", 'w').write(yml)
|
15
|
+
puts "Successfully exported blurbs to #{args[:path]}."
|
16
16
|
else
|
17
17
|
raise "No blurbs have been cached."
|
18
18
|
end
|
@@ -139,6 +139,13 @@ describe CopyTunerClient::I18nBackend do
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
+
context 'non-string key' do
|
143
|
+
it 'Not to be registered in the cache' do
|
144
|
+
expect { subject.translate('en', {}) }.to throw_symbol(:exception)
|
145
|
+
expect(cache).not_to have_key 'en.{}'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
142
149
|
describe "with stored translations" do
|
143
150
|
subject { build_backend }
|
144
151
|
|
@@ -79,7 +79,8 @@ describe CopyTunerClient::ProcessGuard do
|
|
79
79
|
unicorn.spawn
|
80
80
|
end
|
81
81
|
|
82
|
-
|
82
|
+
# FIXME: ruby@2.7以降で失敗するようになっているがテストコードの問題っぽいのでスキップしている
|
83
|
+
xit "flushes when the process terminates" do
|
83
84
|
cache = WritingCache.new
|
84
85
|
pid = fork do
|
85
86
|
process_guard = build_process_guard(cache: cache, preserve_exit_hook: true)
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SonicGarden
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: i18n
|