Skip to content

Commit f158ffc

Browse files
committed
Move ruby version logic to class method
The goal is to install Ruby and Bundler versions before instantiating any "language pack" because the `detect` logic checks if specific gems are installed. By moving moving this logic to a class method, we can decouple it from the detection lifecycle.
1 parent d2a1b99 commit f158ffc

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

lib/language_pack/ruby.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ def compile
8989
remove_vendor_bundle
9090
warn_bundler_upgrade
9191
warn_bad_binstubs
92-
@ruby_version = get_ruby_version
92+
@ruby_version = self.class.get_ruby_version(
93+
metadata: @metadata,
94+
report: @report,
95+
gemfile_lock: @gemfile_lock
96+
)
9397
install_ruby(install_path: slug_vendor_ruby)
9498
setup_language_pack_environment(
9599
ruby_layer_path: File.expand_path("."),
@@ -239,16 +243,16 @@ def ruby_version
239243
@ruby_version or raise "Internal error: @ruby_version is not set. Call `get_ruby_version` and set @ruby_version"
240244
end
241245

242-
def get_ruby_version
246+
def self.get_ruby_version(metadata: , gemfile_lock: , report: HerokuBuildReport::GLOBAL)
243247
last_version_file = "buildpack_ruby_version"
244248
last_version = nil
245-
last_version = @metadata.read(last_version_file).strip if @metadata.exists?(last_version_file)
249+
last_version = metadata.read(last_version_file).strip if metadata.exists?(last_version_file)
246250
# New logic, running in parallel to old logic for reporting differences
247251
lockfile_ruby_version = LanguagePack::RubyVersion.from_gemfile_lock(
248-
ruby: @gemfile_lock.ruby,
252+
ruby: gemfile_lock.ruby,
249253
last_version: last_version
250254
)
251-
@report.capture(
255+
report.capture(
252256
"gemfile_lock.ruby_version.version" => lockfile_ruby_version.ruby_version,
253257
"gemfile_lock.ruby_version.engine" => lockfile_ruby_version.engine,
254258
"gemfile_lock.ruby_version.engine.version" => lockfile_ruby_version.engine_version,

lib/language_pack/test/ruby.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ class LanguagePack::Ruby
77
def compile
88
remove_vendor_bundle
99
warn_bad_binstubs
10-
@ruby_version = get_ruby_version
10+
@ruby_version = self.class.get_ruby_version(
11+
metadata: @metadata,
12+
report: @report,
13+
gemfile_lock: @gemfile_lock
14+
)
1115
install_ruby(install_path: slug_vendor_ruby)
1216
setup_language_pack_environment(
1317
ruby_layer_path: File.expand_path("."),

0 commit comments

Comments
 (0)