Class: Jets::Builders::Md5Zip

Inherits:
Object
  • Object
show all
Includes:
ActiveSupport::NumberHelper, Util
Defined in:
lib/jets/builders/md5_zip.rb

Instance Method Summary collapse

Constructor Details

#initialize(folder) ⇒ Md5Zip

Returns a new instance of Md5Zip.



16
17
18
19
# File 'lib/jets/builders/md5_zip.rb', line 16

def initialize(folder)
  @path = "#{Jets.build_root}/#{folder}"
  @checksum = Md5.checksums[folder]
end

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/jets/builders/md5_zip.rb', line 21

def create
  headline "Creating zip file for #{@path}"
  # => Creating zip file for /tmp/jets/demo/stage/bundled

  # https://serverfault.com/questions/265675/how-can-i-zip-compress-a-symlink
  command = "cd #{@path} && chmod -R 755 . && zip --symlinks -rq #{zip_file} ."
  sh(command)
  # move out of the lower folder to the stage folder
  # mv /tmp/jets/demo/stage/code/code.zip /tmp/jets/demo/stage/code.zip
  FileUtils.mkdir_p(File.dirname(zip_dest))
  FileUtils.mv("#{@path}/#{zip_file}", zip_dest)

  # mv /tmp/jets/demo/stage/zips/code.zip /tmp/jets/demo/stage/zips/code-a8a604aa.zip
  FileUtils.mv(zip_dest, md5_dest)

  file_size = number_to_human_size(File.size(md5_dest))
  puts "Zip file created at: #{md5_dest.color(:green)} (#{file_size})"
end

#md5_destObject

/tmp/jets/demo/stage/zips/code-SHA.zip



53
54
55
# File 'lib/jets/builders/md5_zip.rb', line 53

def md5_dest
  zip_dest.sub(".zip", "-#{@checksum}.zip")
end

#md5_nameObject



57
58
59
# File 'lib/jets/builders/md5_zip.rb', line 57

def md5_name
  File.basename(md5_dest)
end

#zip_destObject

/tmp/jets/demo/stage/zips/code.zip



41
42
43
44
45
46
# File 'lib/jets/builders/md5_zip.rb', line 41

def zip_dest
  stage_area, filename = File.dirname(@path), File.basename(@path)
  zip_area = stage_area + '/zips' # /tmp/jets/demo/stage/zips
  zip_file = filename + '.zip' # code.zip
  "#{zip_area}/#{zip_file}" # /tmp/jets/demo/stage/zips/code.zip
end

#zip_fileObject



48
49
50
# File 'lib/jets/builders/md5_zip.rb', line 48

def zip_file
  File.basename(zip_dest)
end