class SgtnClient::Source
Public Class Methods
getSource(component, key, locale)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 10 def self.getSource(component, key, locale) SgtnClient.logger.debug "[Source][getSource]component=#{component}, key=#{key}, locale=#{locale}" cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale) expired, items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? items = getBundle(component, locale) SgtnClient::CacheUtil.write_cache(cache_key, items) else SgtnClient.logger.debug "[Source][getSource]getting sources from cache with key: " + cache_key end s = (items.nil? || items[locale].nil?)? nil : items[locale][key] if items.nil? || s.nil? SgtnClient.logger.debug "[Source][getSource]source not found, return key: " + key #return key return nil else return s end end
getSources(component, locale)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 30 def self.getSources(component, locale) SgtnClient.logger.debug "[Source][getSources]component=#{component}, locale=#{locale}" cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale) expired, items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? || expired items = getBundle(component, locale) SgtnClient::CacheUtil.write_cache(cache_key, items) else SgtnClient.logger.debug "[Source][getSources]getting sources from cache with key: " + cache_key end return items end
loadBundles(locale)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 43 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 component == '.' || component == '..' yamlfile = File.join(source_bundle, component + "/" + locale + ".yml") bundle = SgtnClient::FileUtil.read_yml(yamlfile) cachekey = SgtnClient::CacheUtil.get_cachekey(component, locale) SgtnClient::CacheUtil.write_cache(cachekey,bundle) end end
Private Class Methods
getBundle(component, locale)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 58 def self.getBundle(component, locale) SgtnClient.logger.debug "[Source][getBundle]component=#{component}, locale=#{locale}" env = SgtnClient::Config.default_environment source_bundle = SgtnClient::Config.configurations[env]["source_bundle"] bundlepath = source_bundle + "/" + component + "/" + locale + ".yml" begin bundle = SgtnClient::FileUtil.read_yml(bundlepath) rescue => exception SgtnClient.logger.error exception.message end return bundle end