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) cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale) items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? items = getBundle(component, locale) SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key SgtnClient::CacheUtil.write_cache(cache_key, items) else SgtnClient.logger.debug "Getting sources from cache with key: " + cache_key end if items.nil? return key end str = items[locale][key] return str end
getSources(component, locale)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 27 def self.getSources(component, locale) cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale) items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? items = getBundle(component, locale) SgtnClient.logger.debug "Putting sources items into cache with key: " + cache_key SgtnClient::CacheUtil.write_cache(cache_key, items) else SgtnClient.logger.debug "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 40 def self.loadBundles(locale) env = SgtnClient::Config.default_environment SgtnClient::Config.configurations.default = locale source_bundle = SgtnClient::Config.configurations[env]["source_bundle"] SgtnClient.logger.debug "Loading [" + locale + "] source bundles from path: " + source_bundle Dir.children(source_bundle).each do |component| yamlfile = File.join(source_bundle, component + "/" + locale + ".yml") bundle = 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 54 def self.getBundle(component, locale) env = SgtnClient::Config.default_environment source_bundle = SgtnClient::Config.configurations[env]["source_bundle"] bundlepath = source_bundle + "/" + component + "/" + locale + ".yml" SgtnClient.logger.debug "Getting source from bundle: " + bundlepath begin bundle = read_yml(bundlepath) rescue => exception SgtnClient.logger.error exception.message end return bundle end
read_yml(file_name)
click to toggle source
# File lib/sgtn-client/api/source.rb, line 67 def self.read_yml(file_name) erb = ERB.new(File.read(file_name)) erb.filename = file_name YAML.load(erb.result) end