Class: Kompo::InstallRuby::FromCache

Inherits:
Taski::Task
  • Object
show all
Defined in:
lib/kompo/tasks/install_ruby.rb

Overview

Restore Ruby from cache Uses the work_dir path saved in metadata to ensure $LOAD_PATH matches

Instance Method Summary collapse

Instance Method Details

#cleanObject



107
108
109
110
111
112
# File 'lib/kompo/tasks/install_ruby.rb', line 107

def clean
  return unless @ruby_install_dir && Dir.exist?(@ruby_install_dir)

  FileUtils.rm_rf(@ruby_install_dir)
  puts "Cleaned up Ruby installation"
end

#runObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/kompo/tasks/install_ruby.rb', line 69

def run
  @ruby_version = Taski.args.fetch(:ruby_version, RUBY_VERSION)
  @ruby_major_minor = ruby_major_and_minor(@ruby_version)

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

  # Use WorkDir.path which now automatically uses cached work_dir path
  work_dir = WorkDir.path

  @ruby_install_dir = File.join(work_dir, "_ruby")
  @ruby_path = File.join(@ruby_install_dir, "bin", "ruby")
  @bundler_path = File.join(@ruby_install_dir, "bin", "bundler")
  @ruby_build_path = File.join(@ruby_install_dir, "_build")
  @original_ruby_install_dir = @ruby_install_dir

  group("Restoring Ruby #{@ruby_version} from cache to #{work_dir}") do
    # Clean up existing files in case work_dir is reused
    FileUtils.rm_rf(@ruby_install_dir) if Dir.exist?(@ruby_install_dir)

    # _build directory is included in cache_install_dir
    FileUtils.cp_r(cache_install_dir, @ruby_install_dir)

    puts "Restored from: #{version_cache_dir}"
  end

  # Fix shebangs in bin scripts to point to the new Ruby path
  fix_bin_shebangs(@ruby_install_dir, @ruby_path)

  # Fix ruby.pc prefix to point to the new install directory
  fix_ruby_pc(@ruby_install_dir)

  puts "Ruby #{@ruby_version} restored from cache"
  version_output, = Open3.capture2(@ruby_path, "--version", err: File::NULL)
  puts "Ruby version: #{version_output.chomp}"
end