class Tr8nCore::Generators::Cache::Base

Attributes

finished_at[RW]
started_at[RW]

Public Instance Methods

api_client() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 70
def api_client
  Tr8n.session.application.api_client
end
application() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 74
def application
  @application ||= api_client.get('applications/current', {:definition => true})
end
cache(key, data) click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 50
def cache(key, data)
  raise Tr8n::Exception.new('Must be implemented by the subclass')
end
cache_application() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 89
def cache_application
  log('Downloading application...')
  cache(Tr8n::Application.cache_key, application)
  log('Application has been cached.')
end
cache_languages() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 95
def cache_languages
  log('Downloading languages...')
  unless application['languages']
    log('No languages are available...')
    return
  end
  languages.each do |lang|
    language = api_client.get("languages/#{lang['locale']}", :definition => true)
    cache(Tr8n::Language.cache_key(language['locale']), language)
  end
  log("#{application['languages'].count} languages have been cached.")
end
cache_path() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 42
def cache_path
  raise Tr8n::Exception.new('Must be implemented by the subclass')
end
cache_version() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 46
def cache_version
  @started_at.strftime('%Y%m%d%H%M%S')
end
execute() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 54
def execute
  raise Tr8n::Exception.new('Must be implemented by the subclass')
end
finalize() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 82
def finalize
  @finished_at = Time.now
  log("Cache has been stored in #{cache_path}")
  log("Cache generation took #{@finished_at - @started_at} mls.")
  log('Done.')
end
languages() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 78
def languages
  application['languages']
end
log(msg) click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 36
def log(msg)
  msg = "#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}: #{msg}"
  puts msg
  Tr8n.logger.debug(msg)
end
prepare() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 64
def prepare
  @started_at = Time.now
  Tr8n.session.init
  cache_path
end
run() click to toggle source
# File lib/tr8n_core/generators/cache/base.rb, line 58
def run
  prepare
  execute
  finalize
end