Class: Jets::Builders::Md5

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/builders/md5.rb

Constant Summary collapse

@@checksums =
{}

Class Method Summary collapse

Class Method Details

.checksumsObject



14
15
16
# File 'lib/jets/builders/md5.rb', line 14

def checksums
  @@checksums
end

.compute!Object



33
34
35
36
37
38
# File 'lib/jets/builders/md5.rb', line 33

def compute!
  stage_folders.each do |path|
    @@checksums[path] = dir(path)
  end
  @@checksums
end

.dir(short_path) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/jets/builders/md5.rb', line 40

def dir(short_path)
  path = "#{Jets.build_root}/#{short_path}"
  files = Dir["#{path}/**/*"]
  files = files.reject { |f| File.directory?(f) }
               .reject { |f| File.symlink?(f) }
  content = files.map do |f|
    Digest::MD5.file(f).to_s[0..7]
  end.join

  # The stage/code md5 sha depends on the other 'symlinked' folders.
  if short_path == "stage/code"
    content += @@checksums.values.join
  end

  md5 = Digest::MD5.new
  md5.update(content)
  md5.hexdigest.to_s[0..7]
end

.folder_exist?(folder) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/jets/builders/md5.rb', line 28

def folder_exist?(folder)
  path = "#{Jets.build_root}/stage/#{folder}"
  File.directory?(path)
end

.stage_foldersObject



18
19
20
21
22
23
24
25
26
# File 'lib/jets/builders/md5.rb', line 18

def stage_folders
  paths = []
  paths << "stage/opt" if folder_exist?("opt")
  paths << "stage/rack" if folder_exist?("rack")
  # Important to have stage/code at the end, since its md5 checksum depends
  # on the previous folders.
  paths << "stage/code"
  paths
end