singleton-client-test 0.7.0.36 → 0.7.0.37

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf77c54658953532871e1efcaeefdd2eeafe82d79d45de57341bc1f36faef8c7
4
- data.tar.gz: '031790359ed9af74295e1679aae41a486da96104ae3a02421494c1a6a3593fd4'
3
+ metadata.gz: 365e6be5a17d3f95f2529789f8632092e859c793c96d67b4f8ddd6492f3e3687
4
+ data.tar.gz: a2df815daeda06f52484e61ef7c64e2c5bc6ce5d46332a10b60187bbc2440a59
5
5
  SHA512:
6
- metadata.gz: 48113ab44d513f63789e7821340fc2de03e8f0c2a73063354ea7fc35b378b8d1f48b22ac3fc4d444c95a810e95a80cee02d8a44866153c82fa39300c1cf142ca
7
- data.tar.gz: 05ba491346a1079a8d4b793d3d7d727aaec7ced066d7410df3b11e8a602700ba46a2fee5504649877db567ee5adaa492ab0bc0702925bad230bd6771b4aeb002
6
+ metadata.gz: 64ef532c3de19ee72c7b0c28661c1192856eb9ebdef0a335d7d702d98b0d7bf56411691cd3ce2c8ceeae829d0d8d8eaad53981cde88721b49e606c657f053028
7
+ data.tar.gz: 27d63abbf9b7df87e20997664eebc97853ae1837f5f3c3853c1f77ce1ace43000d25482ae6f261a3d18788fbba9f026ca75374e1a14c078aa068dbdfec8a532a
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'erb'
5
5
  require 'yaml'
6
-
6
+ require 'observer'
7
7
 
8
8
  module SgtnClient
9
9
  #include Exceptions
@@ -40,6 +40,7 @@ module SgtnClient
40
40
 
41
41
 
42
42
  class Config
43
+ extend Observable
43
44
 
44
45
  attr_accessor :username, :password, :signature, :app_id, :cert_path,
45
46
  :token, :token_secret, :subject,
@@ -182,6 +183,8 @@ module SgtnClient
182
183
  def bundles.locales
183
184
  @locales ||= reduce(Set.new) { |locales, id| locales << id.locale }
184
185
  end
186
+ changed
187
+ notify_observers(:available_locales)
185
188
  end
186
189
  bundles.locales
187
190
  end
@@ -12,12 +12,9 @@ module SgtnClient
12
12
  def load_bundle(component, locale)
13
13
  SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
14
14
 
15
- @single_bundle_loader ||= single_loader { |c,l| super(c,l) }
15
+ @single_bundle_loader ||= single_loader { |c, l| super(c, l) }
16
16
  id = CacheUtil.get_cachekey(component, locale)
17
17
  @single_bundle_loader.operate(id, component, locale)&.value
18
- ensure
19
- # delete thread from hash after finish
20
- @single_bundle_loader.remove_object(id)
21
18
  end
22
19
 
23
20
  def available_bundles
@@ -25,21 +22,26 @@ module SgtnClient
25
22
 
26
23
  @single_available_bundles_loader ||= single_loader { super }
27
24
  @single_available_bundles_loader.operate(CONSTS::AVAILABLE_BUNDLES_KEY)&.value
28
- ensure
29
- @single_available_bundles_loader.remove_object(CONSTS::AVAILABLE_BUNDLES_KEY)
30
25
  end
31
26
 
32
27
  private
28
+
33
29
  def single_loader(&block)
34
- none_alive = proc { |_, thread| thread.nil? || thread.alive? == false }
30
+ loader = nil
31
+ none_alive = proc { |_, thread| thread.nil? }
35
32
  creator = proc do |id, _, *args|
36
33
  Thread.new do
37
34
  SgtnClient.logger.debug "start single loading #{id}"
38
- block.call(*args)
35
+ begin
36
+ block.call(*args)
37
+ ensure
38
+ # delete thread from hash after finish
39
+ loader.remove_object(id)
40
+ end
39
41
  end
40
42
  end
41
43
 
42
- SgtnClient::SingleOperation.new(none_alive, &creator)
44
+ loader = SgtnClient::SingleOperation.new(none_alive, &creator)
43
45
  end
44
46
  end
45
47
  end
@@ -2,6 +2,7 @@
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
4
  require 'pathname'
5
+ require 'psych/simple'
5
6
 
6
7
  module SgtnClient
7
8
  module Common
@@ -24,7 +25,7 @@ module SgtnClient
24
25
  total_messages = {}
25
26
 
26
27
  (@source_bundle_path + component).glob('**/*.{yml, yaml}') do |f|
27
- bundle = YAML.safe_load(File.read(f))
28
+ bundle = Psych.simple_load(File.read(f))
28
29
  messages = bundle&.first&.last # TODO: Warn about inconsistent source locale
29
30
  if messages.is_a?(Hash)
30
31
  total_messages.merge!(messages)
@@ -1,23 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Copyright 2022 VMware, Inc.
2
4
  # SPDX-License-Identifier: EPL-2.0
5
+
3
6
  require 'set'
4
7
 
5
8
  module SgtnClient
6
9
  class LocaleUtil
7
10
  MAP_LOCALES = {
8
- 'zh-CN' => 'zh-Hans',
9
- 'zh-TW' => 'zh-Hant',
10
- 'zh-Hans-CN' => 'zh-Hans',
11
- 'zh-Hant-TW' => 'zh-Hant'
11
+ 'zh-cn' => 'zh-hans',
12
+ 'zh-tw' => 'zh-hant',
13
+ 'zh-hans-cn' => 'zh-hans',
14
+ 'zh-hant-tw' => 'zh-hant'
12
15
  }.freeze
16
+ LOCALE_SEPARATOR = '-'
13
17
 
14
18
  def self.get_best_locale(locale)
19
+ return locale if Config.available_locales.include?(locale)
20
+
15
21
  return get_fallback_locale if locale.nil?
16
22
 
17
23
  locale = locale.to_s
18
24
  return get_fallback_locale if locale.empty?
19
25
 
20
- get_best_match(locale.gsub('_', '-'))
26
+ get_best_match(locale.gsub('_', LOCALE_SEPARATOR).downcase)
21
27
  end
22
28
 
23
29
  def self.is_source_locale(locale = nil)
@@ -26,12 +32,12 @@ module SgtnClient
26
32
 
27
33
  def self.get_best_match(locale)
28
34
  locale = MAP_LOCALES[locale] || locale
29
- return locale if Config.available_locales.include?(locale)
30
-
31
- index = locale.rindex('-')
32
- return get_fallback_locale if index.nil?
35
+ lowercase_locales_map[locale] or begin
36
+ index = locale.rindex(LOCALE_SEPARATOR)
37
+ return get_fallback_locale if index.nil?
33
38
 
34
- get_best_match(locale[0...index])
39
+ get_best_match(locale[0...index])
40
+ end
35
41
  end
36
42
 
37
43
  def self.get_source_locale
@@ -47,6 +53,18 @@ module SgtnClient
47
53
  @fallback_locale ||= get_default_locale || get_source_locale || 'en'
48
54
  end
49
55
 
50
- private_class_method :get_best_match
56
+ def self.lowercase_locales_map
57
+ @lowercase_locales_map ||= Config.available_locales.each_with_object({}) do |locale, memo|
58
+ memo[locale.to_s.downcase] = locale
59
+ end
60
+ end
61
+
62
+ def self.reset_available_locales(type)
63
+ @lowercase_locales_map = nil if type == :available_locales
64
+ end
65
+
66
+ SgtnClient::Config.add_observer(self, :reset_available_locales)
67
+
68
+ private_class_method :get_best_match, :lowercase_locales_map, :reset_available_locales
51
69
  end
52
70
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: singleton-client-test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.36
4
+ version: 0.7.0.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - VMware G11n Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-11 00:00:00.000000000 Z
11
+ date: 2022-05-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -142,6 +142,20 @@ dependencies:
142
142
  - - "~>"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '6.6'
145
+ - !ruby/object:Gem::Dependency
146
+ name: psych-simple
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '2.0'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - "~>"
157
+ - !ruby/object:Gem::Version
158
+ version: '2.0'
145
159
  description: Singleton Ruby client
146
160
  email: g11n-vip-project@vmware.com
147
161
  executables: []