singleton-client-test 0.7.0.39 → 0.7.7.1

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: e774b278cf5b49efb41f194eeb40fab549670a57fbc0197600c272e71f15a795
4
- data.tar.gz: e921a5d1ee1c3535597fca5991ca7c02b210ee731a7b7434f2bcd47cc958d7ef
3
+ metadata.gz: 66531dc1471879c17d807694ff65b64e60bfd35a093d7eb739b728d7e0ae3321
4
+ data.tar.gz: 200e2f4b3ab09a0cfeefe1131ed61494fbec0a1f63974d36a9ce9379d117d066
5
5
  SHA512:
6
- metadata.gz: 3d505a75cea1047514cf6f6bbcc666b26f136307f8bcbe6d2952524c557fd4156bfe29125f9688eb7c9ac8d04237ef344901f9526a5cf8faae39b32439ae3223
7
- data.tar.gz: 0e4ce99bcdcb6ec25d177a8aefd53e28a4beee4f1fe11c4c9be203c4e33e4f66e91d5f790e886a4f542c396acf5fc1355f5ae96e90c22d5387a478f11b1dedbb
6
+ metadata.gz: d85cd8e706659abb1ec1a6e1364b5fcddf2b2c14bca9d616e49d0d28a7657984e26752e48b310763e51f536cbaefb56d99585fe09d46a68cc8cc75f1504e784b
7
+ data.tar.gz: 924846467b0707fb90b95f77a604546822e2e1ae3dbbc79cb3541fdbd1dcc99fd17df0b00762dd5ee2073a08a8f2044cbb260f986ded95e6ca42ce089cf35046
@@ -4,12 +4,10 @@
4
4
  require 'sgtn-client/loader/source'
5
5
 
6
6
  module SgtnClient
7
- autoload :CacheUtil, 'sgtn-client/util/cache-util'
8
-
9
7
  class Source
10
8
  def self.loadBundles(locale)
11
9
  SgtnClient.logger.debug "[Source][loadBundles]locale=#{locale}"
12
- SgtnClient::Config.configurations.default = locale
10
+ Config.configurations.default = locale
13
11
  end
14
12
  end
15
13
  end
@@ -1,6 +1,8 @@
1
1
  # Copyright 2022 VMware, Inc.
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
+ require 'request_store'
5
+
4
6
  module SgtnClient
5
7
  class T
6
8
  def self.s(key)
@@ -43,7 +43,7 @@ module SgtnClient
43
43
  def translate(key, component, locale = nil, **kwargs)
44
44
  SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] key: #{key}, component: #{component}, locale: #{locale}, args: #{kwargs}"
45
45
 
46
- locale = locale.nil? ? self.locale : SgtnClient::LocaleUtil.get_best_locale(locale)
46
+ locale = locale.nil? ? self.locale : LocaleUtil.get_best_locale(locale)
47
47
 
48
48
  result = get_bundle(component, locale)&.fetch(key, nil)
49
49
  if result.nil? && !LocaleUtil.is_source_locale(locale)
@@ -61,7 +61,7 @@ module SgtnClient
61
61
  if kwargs.empty?
62
62
  result
63
63
  else
64
- locale = result.locale if result.is_a?(SgtnClient::StringUtil)
64
+ locale = result.locale if result.is_a?(StringUtil)
65
65
  result.localize(locale) % kwargs
66
66
  end
67
67
  end
@@ -70,7 +70,7 @@ module SgtnClient
70
70
  def get_translations(component, locale = nil)
71
71
  SgtnClient.logger.debug "[#{method(__callee__).owner}.#{__callee__}] component: #{component}, locale: #{locale}"
72
72
 
73
- locale = locale.nil? ? self.locale : SgtnClient::LocaleUtil.get_best_locale(locale)
73
+ locale = locale.nil? ? self.locale : LocaleUtil.get_best_locale(locale)
74
74
  items = get_bundle(component, locale)
75
75
  if items.nil? && !LocaleUtil.is_source_locale(locale)
76
76
  items = get_bundle(component, LocaleUtil.get_source_locale)
@@ -81,11 +81,11 @@ module SgtnClient
81
81
  end
82
82
 
83
83
  def locale
84
- RequestStore.store[:locale] ||= SgtnClient::LocaleUtil.get_fallback_locale
84
+ RequestStore.store[:locale] ||= LocaleUtil.get_fallback_locale
85
85
  end
86
86
 
87
87
  def locale=(value)
88
- RequestStore.store[:locale] = SgtnClient::LocaleUtil.get_best_locale(value)
88
+ RequestStore.store[:locale] = LocaleUtil.get_best_locale(value)
89
89
  end
90
90
 
91
91
  private
@@ -99,13 +99,13 @@ module SgtnClient
99
99
  end
100
100
 
101
101
  def get_bundle!(component, locale)
102
- id = SgtnClient::Common::BundleID.new(component, locale)
103
- bundles = SgtnClient::Config.available_bundles
102
+ id = Common::BundleID.new(component, locale)
103
+ bundles = Config.available_bundles
104
104
  unless bundles.nil? || bundles.empty? || bundles.include?(id)
105
- raise SgtnClient::SingletonError, 'bundle is unavailable.'
105
+ raise SingletonError, 'bundle is unavailable.'
106
106
  end
107
107
 
108
- SgtnClient::Config.loader.get_bundle(component, locale)
108
+ Config.loader.get_bundle(component, locale)
109
109
  end
110
110
  end
111
111
  extend Implementation
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 VMware, Inc.
4
+ # SPDX-License-Identifier: EPL-2.0
5
+
6
+ module SgtnClient
7
+ module Common # :nodoc:
8
+ autoload :BundleID, 'sgtn-client/common/data'
9
+ end
10
+ end
@@ -1,7 +1,7 @@
1
1
  # Copyright 2022 VMware, Inc.
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
- require 'date'
4
+ require 'time'
5
5
 
6
6
  module SgtnClient::Core
7
7
  class Cache
@@ -31,4 +31,4 @@ module SgtnClient::Core
31
31
  end
32
32
  end
33
33
 
34
- end
34
+ end
@@ -3,15 +3,10 @@
3
3
 
4
4
  require 'erb'
5
5
  require 'yaml'
6
+ require 'set'
6
7
  require 'observer'
7
8
 
8
9
  module SgtnClient
9
- #include Exceptions
10
-
11
- module TranslationLoader
12
- autoload :LoaderFactory, 'sgtn-client/loader/loader_factory'
13
- end
14
-
15
10
  module Configuration
16
11
 
17
12
  def config
@@ -130,7 +125,7 @@ module SgtnClient
130
125
  if configurations[env]
131
126
  @@config_cache[env] ||= new(configurations[env])
132
127
  else
133
- raise SgtnClient::Exceptions::MissingConfig.new("Configuration[#{env}] NotFound")
128
+ raise Exceptions::MissingConfig.new("Configuration[#{env}] NotFound")
134
129
  end
135
130
  end
136
131
 
@@ -162,8 +157,8 @@ module SgtnClient
162
157
 
163
158
  def loader
164
159
  @loader ||= begin
165
- config = SgtnClient::Config.configurations[SgtnClient::Config.default_environment]
166
- SgtnClient::TranslationLoader::LoaderFactory.create(config)
160
+ config = Config.configurations[Config.default_environment]
161
+ TranslationLoader::LoaderFactory.create(config)
167
162
  end
168
163
  end
169
164
 
@@ -2,6 +2,7 @@
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
4
  require 'logger'
5
+ require 'time'
5
6
 
6
7
  module SgtnClient
7
8
 
@@ -0,0 +1,46 @@
1
+ # Copyright 2022 VMware, Inc.
2
+ # SPDX-License-Identifier: EPL-2.0
3
+
4
+ require 'i18n'
5
+
6
+ module SgtnClient # :nodoc:
7
+ # When integrating Singleton in a client application that is already using [I18n::Backend (https://www.rubydoc.info/github/svenfuchs/i18n/master/I18n/Backend/), it would be useful to have Singleton override the said module in order to minimize necessary changes. Here is a common usage:
8
+ #
9
+ # I18n::Backend::Simple.include(I18n::Backend::Fallbacks) # add fallbacks behavior to current backend
10
+ # I18n.backend = I18n::Backend::Chain.new(Sgtn::I18nBackend.new(component_name), I18n.backend)
11
+ # I18n.enforce_available_locales=false # disable available locales check
12
+ # I18n.default_locale = :en
13
+ class I18nBackend
14
+ def initialize(component)
15
+ @component = component
16
+ end
17
+
18
+ def initialized?
19
+ @initialized = true
20
+ end
21
+
22
+ def load_translations(*) end
23
+
24
+ def store_translations(*) end
25
+
26
+ def available_locales
27
+ SgtnClient::Config.available_locales.to_a
28
+ end
29
+
30
+ def reload!; end
31
+
32
+ def eager_load!; end
33
+
34
+ def translations; end
35
+
36
+ def exists?(locale, key)
37
+ !!(translate(locale, key) { nil })
38
+ end
39
+
40
+ def translate(locale, key, options)
41
+ flat_key = I18n::Backend::Flatten.normalize_flat_keys(locale, key, options[:scope], '.')
42
+ values = options.except(*I18n::RESERVED_KEYS)
43
+ SgtnClient::Translation.translate(flat_key, @component, locale, **values) { nil }
44
+ end
45
+ end
46
+ end
@@ -4,20 +4,16 @@
4
4
  # SPDX-License-Identifier: EPL-2.0
5
5
 
6
6
  module SgtnClient
7
- autoload :CacheUtil, 'sgtn-client/util/cache-util'
8
-
9
7
  module TranslationLoader
10
- autoload :CONSTS, 'sgtn-client/loader/consts'
11
-
12
8
  module Cache # :nodoc:
13
9
  # get from cache, return expired data immediately
14
10
  def get_bundle(component, locale)
15
11
  SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
16
12
 
17
- key = SgtnClient::CacheUtil.get_cachekey(component, locale)
18
- cache_item = SgtnClient::CacheUtil.get_cache(key)
13
+ key = CacheUtil.get_cachekey(component, locale)
14
+ cache_item = CacheUtil.get_cache(key)
19
15
  if cache_item
20
- if SgtnClient::CacheUtil.is_expired(cache_item)
16
+ if CacheUtil.is_expired(cache_item)
21
17
  Thread.new do # TODO: Use one thread # refresh in background
22
18
  begin
23
19
  load_bundle(component, locale)
@@ -37,22 +33,22 @@ module SgtnClient
37
33
  def load_bundle(component, locale)
38
34
  SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
39
35
 
40
- key = SgtnClient::CacheUtil.get_cachekey(component, locale)
36
+ key = CacheUtil.get_cachekey(component, locale)
41
37
  item = super
42
- SgtnClient::CacheUtil.write_cache(key, item) if item
38
+ CacheUtil.write_cache(key, item) if item
43
39
  item
44
40
  end
45
41
 
46
42
  def available_bundles
47
43
  SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}]"
48
44
 
49
- cache_item = SgtnClient::CacheUtil.get_cache(CONSTS::AVAILABLE_BUNDLES_KEY)
45
+ cache_item = CacheUtil.get_cache(CONSTS::AVAILABLE_BUNDLES_KEY)
50
46
  if cache_item
51
- if SgtnClient::CacheUtil.is_expired(cache_item)
47
+ if CacheUtil.is_expired(cache_item)
52
48
  Thread.new do # TODO: Use one thread
53
49
  begin
54
50
  item = super
55
- SgtnClient::CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
51
+ CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
56
52
  rescue StandardError => e
57
53
  SgtnClient.logger.error 'an error occured while loading available bundles.'
58
54
  SgtnClient.logger.error e
@@ -63,7 +59,7 @@ module SgtnClient
63
59
  end
64
60
 
65
61
  item = super
66
- SgtnClient::CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
62
+ CacheUtil.write_cache(CONSTS::AVAILABLE_BUNDLES_KEY, item) if item
67
63
  item
68
64
  end
69
65
  end
@@ -1,6 +1,8 @@
1
1
  # Copyright 2022 VMware, Inc.
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
+ require 'set'
5
+
4
6
  module SgtnClient
5
7
  module TranslationLoader
6
8
  class Chain
@@ -23,7 +25,7 @@ module SgtnClient
23
25
  end
24
26
  end
25
27
 
26
- raise exception || SgtnClient::SingletonError.new("can't load component: #{component}, locale: #{locale}")
28
+ raise exception || SingletonError.new("can't load component: #{component}, locale: #{locale}")
27
29
  end
28
30
 
29
31
  def available_bundles
@@ -3,14 +3,6 @@
3
3
 
4
4
  module SgtnClient
5
5
  module TranslationLoader
6
- autoload :Source, 'sgtn-client/loader/source'
7
- autoload :SgtnServer, 'sgtn-client/loader/server'
8
- autoload :LocalTranslation, 'sgtn-client/loader/local_translation'
9
- autoload :Chain, 'sgtn-client/loader/chain_loader'
10
- autoload :SourceComparer, 'sgtn-client/loader/source_comparer'
11
- autoload :SingleLoader, 'sgtn-client/loader/single_loader'
12
- autoload :Cache, 'sgtn-client/loader/cache'
13
-
14
6
  module LoaderFactory
15
7
  def self.create(config)
16
8
  SgtnClient.logger.info "[#{method(__callee__).owner}.#{__callee__}] config=#{config}"
@@ -19,7 +11,7 @@ module SgtnClient
19
11
  loaders << Source.new(config) if config['source_bundle']
20
12
  loaders << SgtnServer.new(config) if config['vip_server']
21
13
  loaders << LocalTranslation.new(config) if config['translation_bundle']
22
- raise SgtnClient::SingletonError, 'no translation is available!' if loaders.empty?
14
+ raise SingletonError, 'no translation is available!' if loaders.empty?
23
15
 
24
16
  chain_loader = Class.new(Chain)
25
17
  chain_loader.include SourceComparer
@@ -3,15 +3,10 @@
3
3
 
4
4
  require 'json'
5
5
  require 'pathname'
6
+ require 'set'
6
7
 
7
8
  module SgtnClient
8
- module Common
9
- autoload :BundleID, 'sgtn-client/common/data'
10
- end
11
-
12
9
  module TranslationLoader
13
- autoload :CONSTS, 'sgtn-client/loader/consts'
14
-
15
10
  class LocalTranslation
16
11
  BUNDLE_PREFIX = 'messages_'.freeze
17
12
  BUNDLE_SUFFIX = '.json'.freeze
@@ -29,7 +24,7 @@ module SgtnClient
29
24
  bundle_data = JSON.parse(File.read(file_path))
30
25
  messages = bundle_data['messages']
31
26
 
32
- raise SgtnClient::SingletonError, "no messages in local bundle file: #{file_path}." unless messages
27
+ raise SingletonError, "no messages in local bundle file: #{file_path}." unless messages
33
28
 
34
29
  messages
35
30
  end
@@ -5,15 +5,10 @@
5
5
 
6
6
  require 'faraday'
7
7
  require 'faraday_middleware'
8
+ require 'set'
8
9
 
9
10
  module SgtnClient
10
- module Common
11
- autoload :BundleID, 'sgtn-client/common/data'
12
- end
13
-
14
11
  module TranslationLoader
15
- autoload :CONSTS, 'sgtn-client/loader/consts'
16
-
17
12
  class SgtnServer
18
13
  ERROR_ILLEGAL_DATA = 'server returned illegal data.'
19
14
  ERROR_BUSINESS_ERROR = 'server returned business error.'
@@ -73,7 +68,7 @@ module SgtnClient
73
68
 
74
69
  def extract_data(parsedbody, path_to_data)
75
70
  data = parsedbody.dig('data', *path_to_data)
76
- raise SgtnClient::SingletonError, "no expected data in response. Body is: #{parsedbody}" unless data
71
+ raise SingletonError, "no expected data in response. Body is: #{parsedbody}" unless data
77
72
 
78
73
  data
79
74
  end
@@ -81,13 +76,13 @@ module SgtnClient
81
76
  def process_business_error(parsedbody)
82
77
  b_code = parsedbody.dig('response', 'code')
83
78
  unless b_code >= 200 && b_code < 300 || b_code >= 600 && b_code < 700
84
- raise SgtnClient::SingletonError, "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}"
79
+ raise SingletonError, "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}"
85
80
  end
86
81
 
87
82
  # 600 means a successful response, 6xx means partial successful.
88
83
  SgtnClient.logger.warn "#{ERROR_BUSINESS_ERROR} #{parsedbody['response']}" if b_code > 600
89
84
  rescue TypeError, ArgumentError, NoMethodError => e
90
- raise SgtnClient::SingletonError, "#{ERROR_ILLEGAL_DATA} #{e}. Body is: #{parsedbody}"
85
+ raise SingletonError, "#{ERROR_ILLEGAL_DATA} #{e}. Body is: #{parsedbody}"
91
86
  end
92
87
  end
93
88
  end
@@ -2,12 +2,7 @@
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
4
  module SgtnClient
5
- autoload :SingleOperation, 'sgtn-client/common/single_operation'
6
- autoload :CacheUtil, 'sgtn-client/util/cache-util'
7
-
8
5
  module TranslationLoader
9
- autoload :CONSTS, 'sgtn-client/loader/consts'
10
-
11
6
  module SingleLoader
12
7
  def load_bundle(component, locale)
13
8
  SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
@@ -41,7 +36,7 @@ module SgtnClient
41
36
  end
42
37
  end
43
38
 
44
- loader = SgtnClient::SingleOperation.new(none_alive, &creator)
39
+ loader = SingleOperation.new(none_alive, &creator)
45
40
  end
46
41
  end
47
42
  end
@@ -2,16 +2,11 @@
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
4
  require 'pathname'
5
+ require 'set'
5
6
  require 'yaml'
6
7
 
7
8
  module SgtnClient
8
- module Common
9
- autoload :BundleID, 'sgtn-client/common/data'
10
- end
11
-
12
9
  module TranslationLoader
13
- autoload :CONSTS, 'sgtn-client/loader/consts'
14
-
15
10
  class Source
16
11
  def initialize(config)
17
12
  @source_bundle_path = Pathname.new(config['source_bundle'])
@@ -34,7 +29,7 @@ module SgtnClient
34
29
  end
35
30
  end
36
31
 
37
- raise SgtnClient::SingletonError, "no local source messages for component #{component}" if total_messages.empty?
32
+ raise SingletonError, "no local source messages for component #{component}" if total_messages.empty?
38
33
 
39
34
  total_messages
40
35
  end
@@ -45,7 +40,7 @@ module SgtnClient
45
40
  @available_bundles ||= begin
46
41
  @source_bundle_path.children.select(&:directory?).reduce(Set.new) do |bundles, component|
47
42
  component.glob('**/*.{yml, yaml}') do |_|
48
- bundles << Common::BundleID.new(component.basename.to_s, SgtnClient::LocaleUtil.get_source_locale)
43
+ bundles << Common::BundleID.new(component.basename.to_s, LocaleUtil.get_source_locale)
49
44
  break bundles
50
45
  end || bundles
51
46
  end
@@ -2,12 +2,7 @@
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
4
  module SgtnClient
5
- autoload :StringUtil, 'sgtn-client/util/string-util'
6
- autoload :LocaleUtil, 'sgtn-client/util/locale-util'
7
-
8
5
  module TranslationLoader
9
- autoload :CONSTS, 'sgtn-client/loader/consts'
10
-
11
6
  module SourceComparer
12
7
  def load_bundle(component, locale)
13
8
  SgtnClient.logger.debug "[#{__FILE__}][#{__callee__}] component=#{component}, locale=#{locale}"
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright 2022 VMware, Inc.
4
+ # SPDX-License-Identifier: EPL-2.0
5
+
6
+ module SgtnClient
7
+ module TranslationLoader # :nodoc:
8
+ autoload :Cache, 'sgtn-client/loader/cache'
9
+ autoload :Chain, 'sgtn-client/loader/chain_loader'
10
+ autoload :CONSTS, 'sgtn-client/loader/consts'
11
+ autoload :LoaderFactory, 'sgtn-client/loader/loader_factory'
12
+ autoload :LocalTranslation, 'sgtn-client/loader/local_translation'
13
+ autoload :SgtnServer, 'sgtn-client/loader/server'
14
+ autoload :SingleLoader, 'sgtn-client/loader/single_loader'
15
+ autoload :SourceComparer, 'sgtn-client/loader/source_comparer'
16
+ autoload :Source, 'sgtn-client/loader/source'
17
+ end
18
+ end
@@ -4,9 +4,10 @@
4
4
  module SgtnClient
5
5
  LOGFILE_SHIFT_AGE = 4
6
6
 
7
- module Common
8
- autoload :BundleID, "sgtn-client/common/data"
9
- end
7
+ autoload :Common, 'sgtn-client/common'
8
+ autoload :TranslationLoader, 'sgtn-client/loader'
9
+ autoload :SingleOperation, 'sgtn-client/common/single_operation'
10
+
10
11
  module Core
11
12
  autoload :Cache, "sgtn-client/core/cache"
12
13
  end
@@ -19,9 +20,10 @@ module SgtnClient
19
20
  autoload :Exceptions, "sgtn-client/core/exceptions"
20
21
  autoload :ValidateUtil, "sgtn-client/util/validate-util"
21
22
  autoload :LocaleUtil, "sgtn-client/util/locale-util"
22
- autoload :FileUtil, "sgtn-client/util/file-util"
23
23
  autoload :CacheUtil, "sgtn-client/util/cache-util"
24
- autoload :StringUtil, "sgtn-client/util/string-util"
24
+ autoload :StringUtil, "sgtn-client/util/string-util"
25
+ autoload :SingletonError, 'sgtn-client/exceptions'
26
+ autoload :I18nBackend, "sgtn-client/i18n_backend"
25
27
 
26
28
  module Formatters
27
29
  autoload :PluralFormatter, "sgtn-client/formatters/plurals/plural_formatter"
@@ -30,15 +32,15 @@ module SgtnClient
30
32
 
31
33
  class << self
32
34
  def configure(options = {}, &block)
33
- SgtnClient::Config.configure(options, &block)
35
+ Config.configure(options, &block)
34
36
  end
35
37
 
36
38
  include Logging
37
39
  def load(*args)
38
40
  # load configuration file
39
41
  begin
40
- SgtnClient::Config.load(args[0], args[1])
41
- SgtnClient::ValidateUtil.validate_config()
42
+ Config.load(args[0], args[1])
43
+ ValidateUtil.validate_config()
42
44
  rescue => exception
43
45
  file = File.open('./error.log', 'a')
44
46
  file.sync = true
@@ -48,40 +50,40 @@ module SgtnClient
48
50
 
49
51
  # create log file
50
52
  file = './sgtnclient_d.log'
51
- SgtnClient.logger.debug "[Client][load]create log file=#{file}"
53
+ logger.debug "[Client][load]create log file=#{file}"
52
54
  if args[2] != nil
53
55
  file = args[2]
54
56
  end
55
57
  file = File.open(file, 'a')
56
58
  file.sync = true
57
- SgtnClient.logger = Logger.new(file, LOGFILE_SHIFT_AGE)
59
+ logger = Logger.new(file, LOGFILE_SHIFT_AGE)
58
60
 
59
61
  # Set log level for sandbox mode
60
- env = SgtnClient::Config.default_environment
61
- mode = SgtnClient::Config.configurations[env]["mode"]
62
- SgtnClient.logger.debug "[Client][load]set log level, mode=#{mode}"
62
+ env = Config.default_environment
63
+ mode = Config.configurations[env]["mode"]
64
+ logger.debug "[Client][load]set log level, mode=#{mode}"
63
65
  if mode == 'sandbox'
64
- SgtnClient.logger.level = Logger::DEBUG
66
+ logger.level = Logger::DEBUG
65
67
  else
66
- SgtnClient.logger.level = Logger::INFO
68
+ logger.level = Logger::INFO
67
69
  end
68
70
 
69
71
  # initialize cache
70
- disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
71
- SgtnClient.logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
72
+ disable_cache = Config.configurations[env]["disable_cache"]
73
+ logger.debug "[Client][load]cache initialize, disable_cache=#{disable_cache}"
72
74
  if disable_cache != nil
73
- SgtnClient::Core::Cache.initialize(disable_cache)
75
+ Core::Cache.initialize(disable_cache)
74
76
  else
75
- SgtnClient::Core::Cache.initialize()
77
+ Core::Cache.initialize()
76
78
  end
77
79
  end
78
80
 
79
81
  def logger
80
- SgtnClient::Config.logger
82
+ Config.logger
81
83
  end
82
84
 
83
85
  def logger=(log)
84
- SgtnClient::Config.logger = log
86
+ Config.logger = log
85
87
  end
86
88
  end
87
89
 
@@ -1,34 +1,32 @@
1
1
  # Copyright 2022 VMware, Inc.
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
- module SgtnClient
5
- module Core
6
- autoload :Cache, 'sgtn-client/core/cache'
7
- end
4
+ require 'time'
8
5
 
6
+ module SgtnClient
9
7
  class CacheUtil
10
8
  def self.get_cache(cache_key)
11
- SgtnClient::Core::Cache.get(cache_key)
9
+ Core::Cache.get(cache_key)
12
10
  end
13
11
 
14
12
  def self.clear_cache
15
- SgtnClient::Core::Cache.clear
13
+ Core::Cache.clear
16
14
  end
17
15
 
18
16
  def self.write_cache(cache_key, items)
19
17
  return nil if items.nil? || items.empty?
20
18
 
21
- env = SgtnClient::Config.default_environment
22
- cache_expiry_period = SgtnClient::Config.configurations[env]['cache_expiry_period']
19
+ env = Config.default_environment
20
+ cache_expiry_period = Config.configurations[env]['cache_expiry_period']
23
21
  # expired after 24 hours
24
22
  cache_expiry_period = 24 * 60 if cache_expiry_period.nil?
25
- SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
23
+ Core::Cache.put(cache_key, items, cache_expiry_period)
26
24
  end
27
25
 
28
26
  def self.get_cachekey(component, locale)
29
- env = SgtnClient::Config.default_environment
30
- product_name = SgtnClient::Config.configurations[env]['product_name']
31
- version = SgtnClient::Config.configurations[env]['version'].to_s
27
+ env = Config.default_environment
28
+ product_name = Config.configurations[env]['product_name']
29
+ version = Config.configurations[env]['version'].to_s
32
30
  product_name + '_' + version + '_' + component + '_' + locale
33
31
  end
34
32
 
@@ -3,8 +3,6 @@
3
3
  # Copyright 2022 VMware, Inc.
4
4
  # SPDX-License-Identifier: EPL-2.0
5
5
 
6
- require 'set'
7
-
8
6
  module SgtnClient
9
7
  class LocaleUtil
10
8
  MAP_LOCALES = {
@@ -45,8 +43,8 @@ module SgtnClient
45
43
  end
46
44
 
47
45
  def self.get_default_locale
48
- env = SgtnClient::Config.default_environment
49
- SgtnClient::Config.configurations[env]['default_language']
46
+ env = Config.default_environment
47
+ Config.configurations[env]['default_language']
50
48
  end
51
49
 
52
50
  def self.get_fallback_locale
@@ -63,7 +61,7 @@ module SgtnClient
63
61
  @lowercase_locales_map = nil if type == :available_locales
64
62
  end
65
63
 
66
- SgtnClient::Config.add_observer(self, :reset_available_locales)
64
+ Config.add_observer(self, :reset_available_locales)
67
65
 
68
66
  private_class_method :get_best_match, :lowercase_locales_map, :reset_available_locales
69
67
  end
@@ -6,32 +6,32 @@ module SgtnClient
6
6
  class ValidateUtil
7
7
 
8
8
  def self.validate_config()
9
- env = SgtnClient::Config.default_environment
9
+ env = Config.default_environment
10
10
  SgtnClient.logger.debug "[ValidateUtil][validate_config] env = #{env}"
11
11
  messages = "\n"
12
12
 
13
- mode = SgtnClient::Config.configurations[env]["mode"]
13
+ mode = Config.configurations[env]["mode"]
14
14
  if mode != 'sandbox' && mode != 'live'
15
15
  messages = messages + "Configuration[mode] has to be 'sandbox' or 'live'!\n"
16
16
  end
17
17
 
18
- #version = SgtnClient::Config.configurations[env]["version"]
18
+ #version = Config.configurations[env]["version"]
19
19
  #if version.is_a? Integer
20
20
  #messages = messages + "Configuration[version] has to be standard as '#.#.#, e.g '1.0.0'!\n"
21
21
  #end
22
22
 
23
- cache_expiry_period = SgtnClient::Config.configurations[env]["cache_expiry_period"]
23
+ cache_expiry_period = Config.configurations[env]["cache_expiry_period"]
24
24
  if cache_expiry_period != nil && (cache_expiry_period.is_a? Integer) == false
25
25
  messages = messages + "Configuration[cache_expiry_period] has to be a number!\n"
26
26
  end
27
27
 
28
- disable_cache = SgtnClient::Config.configurations[env]["disable_cache"]
28
+ disable_cache = Config.configurations[env]["disable_cache"]
29
29
  if disable_cache != nil && disable_cache != false && disable_cache != true
30
30
  messages = messages + "Configuration[disable_cache] has to be a 'true' or 'false'!\n"
31
31
  end
32
32
 
33
33
  if messages != "\n"
34
- raise SgtnClient::Exceptions::MissingConfig.new(messages)
34
+ raise Exceptions::MissingConfig.new(messages)
35
35
  end
36
36
  end
37
37
 
@@ -1,15 +1,15 @@
1
1
  # Copyright 2022 VMware, Inc.
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
+ require 'forwardable'
4
5
  require_relative 'singleton-ruby'
5
6
 
6
7
  module Sgtn # :nodoc:
7
- # load configuration from a file
8
- def self.load_config(*args)
9
- SgtnClient.load(*args)
8
+ class << self
9
+ extend Forwardable
10
+ def_delegator SgtnClient, :load, :load_config
11
+ def_delegators SgtnClient::Translation, :translate, :t, :get_translations, :locale, :locale=
10
12
  end
11
13
 
12
- extend SgtnClient::Translation::Implementation
13
-
14
- private_class_method :getString, :getString_p, :getString_f, :getStrings
14
+ I18nBackend = SgtnClient::I18nBackend
15
15
  end
@@ -1,8 +1,7 @@
1
1
  # Copyright 2022 VMware, Inc.
2
2
  # SPDX-License-Identifier: EPL-2.0
3
3
 
4
- require "sgtn-client/sgtn-client"
5
- require 'sgtn-client/cldr/core_ext'
6
4
  require 'twitter_cldr'
5
+ require 'sgtn-client/cldr/core_ext'
7
6
 
8
- require 'sgtn-client/exceptions.rb'
7
+ require 'sgtn-client/sgtn-client'
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.39
4
+ version: 0.7.7.1
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-06-14 00:00:00.000000000 Z
11
+ date: 2022-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
@@ -48,16 +48,16 @@ dependencies:
48
48
  name: rubocop
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
- version: '0.49'
53
+ version: '0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - "~>"
58
+ - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: '0.49'
60
+ version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: webmock
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -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: i18n
147
+ requirement: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ type: :runtime
153
+ prerelease: false
154
+ version_requirements: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
145
159
  description: Singleton Ruby client
146
160
  email: g11n-vip-project@vmware.com
147
161
  executables: []
@@ -158,6 +172,7 @@ files:
158
172
  - lib/sgtn-client/cldr/localized_datetime.rb
159
173
  - lib/sgtn-client/cldr/localized_str.rb
160
174
  - lib/sgtn-client/cldr/localized_time.rb
175
+ - lib/sgtn-client/common.rb
161
176
  - lib/sgtn-client/common/data.rb
162
177
  - lib/sgtn-client/common/single_operation.rb
163
178
  - lib/sgtn-client/core/cache.rb
@@ -166,6 +181,8 @@ files:
166
181
  - lib/sgtn-client/core/logging.rb
167
182
  - lib/sgtn-client/exceptions.rb
168
183
  - lib/sgtn-client/formatters/plurals/plural_formatter.rb
184
+ - lib/sgtn-client/i18n_backend.rb
185
+ - lib/sgtn-client/loader.rb
169
186
  - lib/sgtn-client/loader/cache.rb
170
187
  - lib/sgtn-client/loader/chain_loader.rb
171
188
  - lib/sgtn-client/loader/consts.rb