Class: SgtnClient::Config

Inherits:
Object
  • Object
show all
Includes:
Observable, Singleton
Defined in:
lib/sgtn-client/core/config.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cache_expiry_periodObject

Returns the value of attribute cache_expiry_period.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def cache_expiry_period
  @cache_expiry_period
end

#log_fileObject

Returns the value of attribute log_file.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def log_file
  @log_file
end

#log_levelObject

Returns the value of attribute log_level.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def log_level
  @log_level
end

#loggerObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/sgtn-client/core/config.rb', line 22

def logger
  @logger ||= if log_file
                puts "create log file: '#{log_file}', level: #{log_level}"
                require 'logging'
                logger = Logging.logger(log_file, 4, 1_048_576)
                logger.level = log_level
                logger
              else
                require 'logger'
                Logger.new(STDOUT, level: log_level || Logger::INFO)
              end
end

#product_nameObject

Returns the value of attribute product_name.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def product_name
  @product_name
end

#pseudo_tagObject



18
19
20
# File 'lib/sgtn-client/core/config.rb', line 18

def pseudo_tag
  @pseudo_tag ||= '@@'
end

#source_bundleObject

Returns the value of attribute source_bundle.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def source_bundle
  @source_bundle
end

#translation_bundleObject

Returns the value of attribute translation_bundle.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def translation_bundle
  @translation_bundle
end

#versionObject

Returns the value of attribute version.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def version
  @version
end

#vip_serverObject

Returns the value of attribute vip_server.



14
15
16
# File 'lib/sgtn-client/core/config.rb', line 14

def vip_server
  @vip_server
end

Instance Method Details

#available_bundlesObject



39
40
41
42
43
44
45
# File 'lib/sgtn-client/core/config.rb', line 39

def available_bundles
  loader.available_bundles
rescue StandardError => e
  SgtnClient.logger.error 'failed to get available bundles'
  SgtnClient.logger.error e
  Set.new
end

#available_componentsObject



47
48
49
50
51
52
53
# File 'lib/sgtn-client/core/config.rb', line 47

def available_components
  bundles = available_bundles
  return Set.new if bundles.nil? || bundles.empty?

  define_bundles_methods(bundles) unless bundles.respond_to?(:components)
  bundles.components
end

#available_locales(component) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/sgtn-client/core/config.rb', line 55

def available_locales(component)
  bundles = available_bundles
  return Set.new if bundles.nil? || bundles.empty?

  define_bundles_methods(bundles) unless bundles.respond_to?(:locales)
  bundles.locales(component)
end

#loaderObject



35
36
37
# File 'lib/sgtn-client/core/config.rb', line 35

def loader
  @loader ||= TranslationLoader::LoaderFactory.create(self)
end

#update(options) ⇒ Object



63
64
65
66
67
# File 'lib/sgtn-client/core/config.rb', line 63

def update(options)
  options.each do |key, value|
    send("#{key}=", value)
  end
end