Class: SgtnClient::Source
- Inherits:
-
Object
- Object
- SgtnClient::Source
- Defined in:
- lib/sgtn-client/api/source.rb
Class Method Summary collapse
- .getBundle(component) ⇒ Object
- .getSource(component, key) ⇒ Object
- .loadBundles(locale) ⇒ Object
- .read_yml(file_name) ⇒ Object
Class Method Details
.getBundle(component) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/sgtn-client/api/source.rb', line 43 def self.getBundle(component) env = SgtnClient::Config.default_environment source_bundle = SgtnClient::Config.configurations[env]["source_bundle"] bundlepath = source_bundle + "/" + component + "/en.yml" SgtnClient.logger.debug "Getting source from bundle: " + bundlepath begin bundle = read_yml(bundlepath) rescue => exception SgtnClient.logger.error exception. end return bundle end |
.getSource(component, key) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sgtn-client/api/source.rb', line 10 def self.getSource(component, key) locale = "en" cache_key = SgtnClient::CacheUtil.get_cachekey(component, locale) items = SgtnClient::CacheUtil.get_cache(cache_key) if items.nil? items = getBundle(component) 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 |
.loadBundles(locale) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sgtn-client/api/source.rb', line 28 def self.loadBundles(locale) env = SgtnClient::Config.default_environment source_bundle = SgtnClient::Config.configurations[env]["source_bundle"] SgtnClient.logger.debug "Loading [" + locale + "] 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 |
.read_yml(file_name) ⇒ Object
56 57 58 59 60 |
# File 'lib/sgtn-client/api/source.rb', line 56 def self.read_yml(file_name) erb = ERB.new(File.read(file_name)) erb.filename = file_name YAML.load(erb.result) end |