Class: SgtnClient::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/sgtn-client/api/source.rb

Class Method Summary collapse

Class Method Details

.getSource(component, key, locale) ⇒ Object



8
9
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 8

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
  s = items[locale][key]
  if items.nil? || s.nil?
    SgtnClient.logger.debug "Source not found, return key: " + key
    #return key
    return nil
  else
    return s
  end
end

.getSources(component, 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.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) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/sgtn-client/api/source.rb', line 41

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.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