Class: Kompo::InstallRuby::FromSource

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

Overview

Build Ruby from source using ruby-build Ruby is built into work_dir with –prefix=work_dir/_ruby. After building, the result is cached with the work_dir path preserved in metadata. When using cache, the same work_dir path is recreated to ensure $LOAD_PATH matches.

Instance Method Summary collapse

Instance Method Details

#cleanObject



180
181
182
183
184
185
# File 'lib/kompo/tasks/install_ruby.rb', line 180

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



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/kompo/tasks/install_ruby.rb', line 158

def run
  ruby_build = RubyBuildPath.path

  @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)

  # Check if we have a valid cache
   = File.join(@version_cache_dir, "metadata.json")
  if cache_valid?()
    restore_from_cache()
  else
    build_and_cache(ruby_build)
  end

  puts "Ruby installed at: #{@ruby_install_dir}"
  version_output, = Open3.capture2(@ruby_path, "--version", err: File::NULL)
  puts "Ruby version: #{version_output.chomp}"
end