Class: Tml::Generators::File

Inherits:
Base
  • Object
show all
Defined in:
lib/tml/generators/file.rb

Instance Attribute Summary

Attributes inherited from Base

#finished_at, #started_at

Instance Method Summary collapse

Methods inherited from Base

#api_client, #application, #cache, #cache_path, #cache_version, #current_path, #finalize, #languages, #log, #prepare, #run, #ungzip, #untar

Instance Method Details

#executeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tml/generators/file.rb', line 40

def execute
  if cache_version == '0'
    log('No releases have been generated yet. Please visit your Dashboard and publish translations.')
  else
    log("Current cache version: #{cache_version}")

    archive_name = "#{cache_version}.tar.gz"
    path = "#{cache_path}/#{archive_name}"
    url = "#{api_client.application.cdn_host}/#{Tml.config.application[:key]}/#{archive_name}"

    log("Downloading cache file: #{url}")
    open(path, 'wb') do |file|
      file << open(url).read
    end

    log('Extracting cache file...')
    version_path = "#{cache_path}/#{cache_version}"
    untar(ungzip(File.new(path)), version_path)
    log("Cache has been stored in #{version_path}")

    File.unlink(path)

    begin
      FileUtils.rm(current_path) if File.exist?(current_path)
      FileUtils.ln_s(cache_version, current_path)
      log('The new cache path has been marked as current')
    rescue
      log('Could not generate current symlink to the cach path. Please indicate the version manually in the Tml initializer.')
    end
  end
end