class SgtnClient::Source
Public Class Methods
loadBundles(locale)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 10 def self.loadBundles(locale) SgtnClient.logger.debug "[Source][loadBundles]locale=#{locale}" env = SgtnClient::Config.default_environment SgtnClient::Config.configurations.default = locale source_bundle = SgtnClient::Config.configurations[env]['source_bundle'] Dir.foreach(source_bundle) do |component| next if %w[. ..].include? component bundle = load_bundle(component) cachekey = SgtnClient::CacheUtil.get_cachekey(component, LocaleUtil.get_source_locale) SgtnClient::CacheUtil.write_cache(cachekey, bundle) end end
load_bundle(component)
click to toggle source
# File lib/sgtn-client/loader/local_source_bundle.rb, line 6 def self.load_bundle(component) SgtnClient.logger.debug "[Source][getBundle]component=#{component}" env = SgtnClient::Config.default_environment source_bundle = SgtnClient::Config.configurations[env]['source_bundle'] component_path = "#{source_bundle}/#{component}" total_messages = nil Dir.glob('**/*.{yml, yaml}', base: component_path) do |f| bundle = SgtnClient::FileUtil.read_yml("#{component_path}/#{f}") if total_messages.nil? total_messages = bundle&.first&.last else total_messages.merge!(bundle&.first&.last) end end if total_messages return { 'component' => component, 'locale' => SgtnClient::LocaleUtil.get_source_locale, 'messages' => total_messages } end rescue StandardError => e SgtnClient.logger.error e.message nil end