singleton-client-test 0.7.7.3 → 0.7.7.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sgtn-client/api/source.rb +0 -3
- data/lib/sgtn-client/api/t.rb +2 -0
- data/lib/sgtn-client/api/translation.rb +40 -36
- data/lib/sgtn-client/common/data.rb +40 -3
- data/lib/sgtn-client/common/single_operation.rb +7 -8
- data/lib/sgtn-client/common.rb +10 -0
- data/lib/sgtn-client/core/config.rb +57 -174
- data/lib/sgtn-client/i18n_backend.rb +48 -0
- data/lib/sgtn-client/loader/cache.rb +30 -46
- data/lib/sgtn-client/loader/chain_loader.rb +3 -1
- data/lib/sgtn-client/loader/loader_factory.rb +6 -13
- data/lib/sgtn-client/loader/local_translation.rb +5 -10
- data/lib/sgtn-client/loader/server.rb +23 -32
- data/lib/sgtn-client/loader/single_loader.rb +22 -24
- data/lib/sgtn-client/loader/source.rb +6 -11
- data/lib/sgtn-client/loader/source_comparer.rb +1 -6
- data/lib/sgtn-client/loader.rb +19 -0
- data/lib/sgtn-client/sgtn-client.rb +46 -84
- data/lib/sgtn-client/util/locale-util.rb +60 -28
- data/lib/sgtn-client/util/string-util.rb +5 -2
- data/lib/sgtn-client/util/validate-util.rb +10 -20
- data/lib/singleton-client.rb +31 -6
- data/lib/singleton-ruby.rb +2 -3
- metadata +23 -43
- data/lib/sgtn-client/core/cache.rb +0 -34
- data/lib/sgtn-client/core/logging.rb +0 -52
- data/lib/sgtn-client/util/cache-util.rb +0 -40
@@ -6,32 +6,22 @@ module SgtnClient
|
|
6
6
|
class ValidateUtil
|
7
7
|
|
8
8
|
def self.validate_config()
|
9
|
-
|
10
|
-
|
11
|
-
messages = "\n"
|
9
|
+
puts "validating config..."
|
10
|
+
messages = ""
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
12
|
+
version = SgtnClient.config.version
|
13
|
+
SgtnClient.config.version = version.to_s
|
14
|
+
if version.to_s !~ /\A(\d+\.)*\d+\z/
|
15
|
+
messages = messages + "Configuration[version] has to be standard as '#.#.#, e.g '1.0.0'!\n"
|
16
16
|
end
|
17
|
-
|
18
|
-
#version = SgtnClient::Config.configurations[env]["version"]
|
19
|
-
#if version.is_a? Integer
|
20
|
-
#messages = messages + "Configuration[version] has to be standard as '#.#.#, e.g '1.0.0'!\n"
|
21
|
-
#end
|
22
17
|
|
23
|
-
cache_expiry_period = SgtnClient
|
18
|
+
cache_expiry_period = SgtnClient.config.cache_expiry_period
|
24
19
|
if cache_expiry_period != nil && (cache_expiry_period.is_a? Integer) == false
|
25
20
|
messages = messages + "Configuration[cache_expiry_period] has to be a number!\n"
|
26
21
|
end
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
messages = messages + "Configuration[disable_cache] has to be a 'true' or 'false'!\n"
|
31
|
-
end
|
32
|
-
|
33
|
-
if messages != "\n"
|
34
|
-
raise SgtnClient::Exceptions::MissingConfig.new(messages)
|
22
|
+
|
23
|
+
if messages != ""
|
24
|
+
raise Exceptions::MissingConfig.new(messages)
|
35
25
|
end
|
36
26
|
end
|
37
27
|
|
data/lib/singleton-client.rb
CHANGED
@@ -1,15 +1,40 @@
|
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
class << self
|
9
|
+
extend Forwardable
|
10
|
+
|
11
|
+
# load configurations from a file
|
12
|
+
def load_config(config_file, env)
|
13
|
+
SgtnClient.load(config_file, env)
|
14
|
+
end
|
11
15
|
|
12
|
-
|
16
|
+
def_delegator SgtnClient::Config, :instance, :config
|
17
|
+
delegate %i[translate t get_translations] => SgtnClient::Translation,
|
18
|
+
%i[locale locale=] => SgtnClient,
|
19
|
+
%i[logger product_name version vip_server translation_bundle
|
20
|
+
source_bundle cache_expiry_period log_file log_level].flat_map { |m|
|
21
|
+
[m, "#{m}=".to_sym]
|
22
|
+
} => :config
|
23
|
+
|
24
|
+
def with_locale(tmp_locale = nil)
|
25
|
+
if tmp_locale.nil?
|
26
|
+
yield
|
27
|
+
else
|
28
|
+
current_locale = locale
|
29
|
+
self.locale = tmp_locale
|
30
|
+
begin
|
31
|
+
yield
|
32
|
+
ensure
|
33
|
+
self.locale = current_locale
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
13
38
|
|
14
|
-
|
39
|
+
I18nBackend = SgtnClient::I18nBackend
|
15
40
|
end
|
data/lib/singleton-ruby.rb
CHANGED
@@ -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/
|
7
|
+
require 'sgtn-client/sgtn-client'
|
metadata
CHANGED
@@ -1,79 +1,59 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: singleton-client-test
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.7.
|
4
|
+
version: 0.7.7.6
|
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-
|
11
|
+
date: 2022-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: concurrent-ruby
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: '6.0'
|
23
|
-
type: :development
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
24
|
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: '6.0'
|
33
|
-
- !ruby/object:Gem::Dependency
|
34
|
-
name: rspec
|
35
|
-
requirement: !ruby/object:Gem::Requirement
|
36
|
-
requirements:
|
37
|
-
- - "~>"
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: '3.0'
|
40
|
-
type: :development
|
41
|
-
prerelease: false
|
42
|
-
version_requirements: !ruby/object:Gem::Requirement
|
43
|
-
requirements:
|
44
|
-
- - "~>"
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '3.0'
|
26
|
+
version: '0'
|
47
27
|
- !ruby/object:Gem::Dependency
|
48
|
-
name:
|
28
|
+
name: faraday
|
49
29
|
requirement: !ruby/object:Gem::Requirement
|
50
30
|
requirements:
|
51
31
|
- - "~>"
|
52
32
|
- !ruby/object:Gem::Version
|
53
|
-
version: '
|
54
|
-
type: :
|
33
|
+
version: '1.10'
|
34
|
+
type: :runtime
|
55
35
|
prerelease: false
|
56
36
|
version_requirements: !ruby/object:Gem::Requirement
|
57
37
|
requirements:
|
58
38
|
- - "~>"
|
59
39
|
- !ruby/object:Gem::Version
|
60
|
-
version: '
|
40
|
+
version: '1.10'
|
61
41
|
- !ruby/object:Gem::Dependency
|
62
|
-
name:
|
42
|
+
name: faraday_middleware
|
63
43
|
requirement: !ruby/object:Gem::Requirement
|
64
44
|
requirements:
|
65
45
|
- - "~>"
|
66
46
|
- !ruby/object:Gem::Version
|
67
|
-
version: '2
|
68
|
-
type: :
|
47
|
+
version: '1.2'
|
48
|
+
type: :runtime
|
69
49
|
prerelease: false
|
70
50
|
version_requirements: !ruby/object:Gem::Requirement
|
71
51
|
requirements:
|
72
52
|
- - "~>"
|
73
53
|
- !ruby/object:Gem::Version
|
74
|
-
version: '2
|
54
|
+
version: '1.2'
|
75
55
|
- !ruby/object:Gem::Dependency
|
76
|
-
name:
|
56
|
+
name: i18n
|
77
57
|
requirement: !ruby/object:Gem::Requirement
|
78
58
|
requirements:
|
79
59
|
- - ">="
|
@@ -87,7 +67,7 @@ dependencies:
|
|
87
67
|
- !ruby/object:Gem::Version
|
88
68
|
version: '0'
|
89
69
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
70
|
+
name: logging
|
91
71
|
requirement: !ruby/object:Gem::Requirement
|
92
72
|
requirements:
|
93
73
|
- - ">="
|
@@ -118,16 +98,16 @@ dependencies:
|
|
118
98
|
name: request_store
|
119
99
|
requirement: !ruby/object:Gem::Requirement
|
120
100
|
requirements:
|
121
|
-
- - "
|
101
|
+
- - "~>"
|
122
102
|
- !ruby/object:Gem::Version
|
123
|
-
version: '0'
|
103
|
+
version: '1.0'
|
124
104
|
type: :runtime
|
125
105
|
prerelease: false
|
126
106
|
version_requirements: !ruby/object:Gem::Requirement
|
127
107
|
requirements:
|
128
|
-
- - "
|
108
|
+
- - "~>"
|
129
109
|
- !ruby/object:Gem::Version
|
130
|
-
version: '0'
|
110
|
+
version: '1.0'
|
131
111
|
- !ruby/object:Gem::Dependency
|
132
112
|
name: twitter_cldr
|
133
113
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,14 +138,15 @@ files:
|
|
158
138
|
- lib/sgtn-client/cldr/localized_datetime.rb
|
159
139
|
- lib/sgtn-client/cldr/localized_str.rb
|
160
140
|
- lib/sgtn-client/cldr/localized_time.rb
|
141
|
+
- lib/sgtn-client/common.rb
|
161
142
|
- lib/sgtn-client/common/data.rb
|
162
143
|
- lib/sgtn-client/common/single_operation.rb
|
163
|
-
- lib/sgtn-client/core/cache.rb
|
164
144
|
- lib/sgtn-client/core/config.rb
|
165
145
|
- lib/sgtn-client/core/exceptions.rb
|
166
|
-
- lib/sgtn-client/core/logging.rb
|
167
146
|
- lib/sgtn-client/exceptions.rb
|
168
147
|
- lib/sgtn-client/formatters/plurals/plural_formatter.rb
|
148
|
+
- lib/sgtn-client/i18n_backend.rb
|
149
|
+
- lib/sgtn-client/loader.rb
|
169
150
|
- lib/sgtn-client/loader/cache.rb
|
170
151
|
- lib/sgtn-client/loader/chain_loader.rb
|
171
152
|
- lib/sgtn-client/loader/consts.rb
|
@@ -176,7 +157,6 @@ files:
|
|
176
157
|
- lib/sgtn-client/loader/source.rb
|
177
158
|
- lib/sgtn-client/loader/source_comparer.rb
|
178
159
|
- lib/sgtn-client/sgtn-client.rb
|
179
|
-
- lib/sgtn-client/util/cache-util.rb
|
180
160
|
- lib/sgtn-client/util/locale-util.rb
|
181
161
|
- lib/sgtn-client/util/string-util.rb
|
182
162
|
- lib/sgtn-client/util/validate-util.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
# Copyright 2022 VMware, Inc.
|
2
|
-
# SPDX-License-Identifier: EPL-2.0
|
3
|
-
|
4
|
-
require 'date'
|
5
|
-
|
6
|
-
module SgtnClient::Core
|
7
|
-
class Cache
|
8
|
-
Entry = Struct.new(:expiry, :items)
|
9
|
-
|
10
|
-
def self.initialize(disabled=false, opts={})
|
11
|
-
@@opts = opts
|
12
|
-
SgtnClient.logger.debug "[Cache][initialize] Disable cache? #{disabled}"
|
13
|
-
@@data = Hash.new
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.get(key)
|
17
|
-
SgtnClient.logger.debug "[Cache][get]get cache for key: " + key
|
18
|
-
return @@data&.dig(key)
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.put(key, items, ttl=nil)
|
22
|
-
ttl ||= @@opts[:ttl]
|
23
|
-
# hours from new
|
24
|
-
SgtnClient.logger.debug "[Cache][put]put cache for key '" + key + "' with expired time at'" + (Time.now + ttl*60).to_s
|
25
|
-
@@data[key] = Entry.new(Time.now + ttl*60, items)
|
26
|
-
end
|
27
|
-
|
28
|
-
def self.clear
|
29
|
-
SgtnClient.logger.debug "[Cache][clear]clear cache!"
|
30
|
-
@@data = Hash.new
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# Copyright 2022 VMware, Inc.
|
2
|
-
# SPDX-License-Identifier: EPL-2.0
|
3
|
-
|
4
|
-
require 'logger'
|
5
|
-
|
6
|
-
module SgtnClient
|
7
|
-
|
8
|
-
# Include Logging module to provide logger functionality.
|
9
|
-
# == Configure logger
|
10
|
-
# Logging.logger = Logger.new(STDERR)
|
11
|
-
#
|
12
|
-
# == Example
|
13
|
-
# include Logger
|
14
|
-
# logger.info "Debug message"
|
15
|
-
module Logging
|
16
|
-
|
17
|
-
# Get logger object
|
18
|
-
def logger
|
19
|
-
@logger ||= Logging.logger
|
20
|
-
end
|
21
|
-
|
22
|
-
def log_event(message, &block)
|
23
|
-
start_time = Time.now
|
24
|
-
block.call
|
25
|
-
ensure
|
26
|
-
logger.info sprintf("[%.3fs] %s", Time.now - start_time, message)
|
27
|
-
end
|
28
|
-
|
29
|
-
class << self
|
30
|
-
|
31
|
-
# Get or Create configured logger based on the default environment configuration
|
32
|
-
def logger
|
33
|
-
@logger ||= Logger.new(STDERR)
|
34
|
-
end
|
35
|
-
|
36
|
-
# Set logger directly and clear the loggers cache.
|
37
|
-
# === Attributes
|
38
|
-
# * <tt>logger</tt> -- Logger object
|
39
|
-
# === Example
|
40
|
-
# Logging.logger = Logger.new(STDERR)
|
41
|
-
def logger=(logger)
|
42
|
-
@logger = logger
|
43
|
-
if Config.config.mode.eql? 'live' and @logger.level == Logger::DEBUG
|
44
|
-
@logger.warn "DEBUG log level not allowed in live mode for security of confidential information. Changing log level to INFO..."
|
45
|
-
@logger.level = Logger::INFO
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
# Copyright 2022 VMware, Inc.
|
2
|
-
# SPDX-License-Identifier: EPL-2.0
|
3
|
-
|
4
|
-
module SgtnClient
|
5
|
-
module Core
|
6
|
-
autoload :Cache, 'sgtn-client/core/cache'
|
7
|
-
end
|
8
|
-
|
9
|
-
class CacheUtil
|
10
|
-
def self.get_cache(cache_key)
|
11
|
-
SgtnClient::Core::Cache.get(cache_key)
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.clear_cache
|
15
|
-
SgtnClient::Core::Cache.clear
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.write_cache(cache_key, items)
|
19
|
-
return nil if items.nil? || items.empty?
|
20
|
-
|
21
|
-
env = SgtnClient::Config.default_environment
|
22
|
-
cache_expiry_period = SgtnClient::Config.configurations[env]['cache_expiry_period']
|
23
|
-
# expired after 24 hours
|
24
|
-
cache_expiry_period = 24 * 60 if cache_expiry_period.nil?
|
25
|
-
SgtnClient::Core::Cache.put(cache_key, items, cache_expiry_period)
|
26
|
-
end
|
27
|
-
|
28
|
-
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
|
32
|
-
product_name + '_' + version + '_' + component + '_' + locale
|
33
|
-
end
|
34
|
-
|
35
|
-
def self.is_expired(cache_item)
|
36
|
-
cache_item[:expiry] < Time.now
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|