Class: Jets::Builders::Purger

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

Instance Method Summary collapse

Constructor Details

#initializePurger

Returns a new instance of Purger.



4
5
6
7
# File 'lib/jets/builders/purger.rb', line 4

def initialize
  @project_name = Jets.config.project_name
  @version_file = "/tmp/jets/#{@project_name}/jets_version.txt"
end

Instance Method Details

#purgeObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/jets/builders/purger.rb', line 9

def purge
  if version_changed?
    last_version = @last_version || "unknown"
    puts "The jets version has changed enough since the last build to merit refreshing the build cache."
    puts "Current jets version: #{Jets::VERSION} Last built jets version: #{last_version}"
    puts "Removing /tmp/jets/#{@project_name} to start fresh."
    FileUtils.rm_rf("/tmp/jets/#{@project_name}")
  end
  write_version
end

#version_changed?Boolean

When jets changes versions major or minor version consider it a big enough can to purge the cache

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/jets/builders/purger.rb', line 21

def version_changed?
  return true unless File.exist?(@version_file)

  @last_version = IO.read(@version_file).strip
  last_major, last_minor, _ = @last_version.split('.')
  current_major, current_minor, _ = Jets::VERSION.split('.')
  last_major != current_major || last_minor != current_minor
end

#write_versionObject



30
31
32
33
# File 'lib/jets/builders/purger.rb', line 30

def write_version
  FileUtils.mkdir_p(File.dirname(@version_file))
  IO.write(@version_file, Jets::VERSION)
end