Class: Kompo::BundleInstall::FromCache

Inherits:
Taski::Task
  • Object
show all
Includes:
Kompo::BundleCacheHelpers
Defined in:
lib/kompo/tasks/bundle_install.rb

Overview

Restore bundle from cache

Instance Method Summary collapse

Instance Method Details

#cleanObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/kompo/tasks/bundle_install.rb', line 83

def clean
  work_dir = WorkDir.path
  return unless work_dir && Dir.exist?(work_dir)

  [@bundle_ruby_dir, @bundler_config_path].each do |path|
    next unless path

    FileUtils.rm_rf(path) if File.exist?(path)
  end
  puts "Cleaned up bundle installation"
end

#runObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/kompo/tasks/bundle_install.rb', line 52

def run
  work_dir = WorkDir.path
  ruby_major_minor = InstallRuby.ruby_major_minor

  @bundle_ruby_dir = File.join(work_dir, "bundle", "ruby", "#{ruby_major_minor}.0")
  @bundler_config_path = File.join(work_dir, ".bundle", "config")

  kompo_cache = Taski.args.fetch(:kompo_cache, File.expand_path("~/.kompo/cache"))
  ruby_version = InstallRuby.ruby_version
  version_cache_dir = File.join(kompo_cache, ruby_version)

  bundle_cache_name = compute_bundle_cache_name
  raise "Gemfile.lock not found in #{work_dir}" unless bundle_cache_name

  cache_dir = File.join(version_cache_dir, bundle_cache_name)

  group("Restoring bundle from cache") do
    # Clean up existing files in case work_dir is reused
    FileUtils.rm_rf(File.join(work_dir, "bundle")) if Dir.exist?(File.join(work_dir, "bundle"))
    FileUtils.rm_rf(File.join(work_dir, ".bundle")) if Dir.exist?(File.join(work_dir, ".bundle"))

    # Copy from cache
    FileUtils.cp_r(File.join(cache_dir, "bundle"), File.join(work_dir, "bundle"))
    FileUtils.cp_r(File.join(cache_dir, ".bundle"), File.join(work_dir, ".bundle"))

    puts "Restored from: #{cache_dir}"
  end

  puts "Bundle restored from cache"
end