Class: Batali::Command::Cache

Inherits:
Batali::Command show all
Defined in:
lib/batali/command/cache.rb

Overview

Cache management and information

Constant Summary

Constants inherited from Batali::Command

DEFAULT_CONFIGURATION_FILES

Instance Method Summary collapse

Methods inherited from Batali::Command

#batali_file, #cache_directory, #dry_run, #infrastructure?, #initialize, #manifest

Constructor Details

This class inherits a constructor from Batali::Command

Instance Method Details

#displayObject

Display local cache information



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/batali/command/cache.rb', line 28

def display
  cache_size = Dir.glob(File.join(cache_directory, '**', '**', '*')).map do |path|
    File.size(path) if File.file?(path)
  end.compact.inject(&:+).to_i
  cache_size = "#{sprintf('%.2f', ((cache_size / 1024.to_f) / 1024))}M"
  [
    "#{ui.color('Path:', :bold)} #{cache_directory}",
    "#{ui.color('Size:', :bold)} #{cache_size}"
  ].each do |line|
    ui.puts "  #{line}"
  end
end

#execute!Object

Display information from manifest



10
11
12
13
14
15
16
# File 'lib/batali/command/cache.rb', line 10

def execute!
  if(opts[:scrub])
    scrub!
  end
  ui.puts ui.color('Batali cache information:', :bold) + "\n"
  display
end

#scrub!Object

Remove all contents from local cache



19
20
21
22
23
24
25
# File 'lib/batali/command/cache.rb', line 19

def scrub!
  ui.confirm "Remove all contents from local cache (#{cache_directory})"
  run_action 'Scrubbing local cache' do
    FileUtils.rm_rf(cache_directory)
    nil
  end
end