Skip to content

Commit 6b5e358

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 f158ffc commit 6b5e358

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

lib/language_pack/ruby.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ def best_practice_warnings
8686
end
8787

8888
def compile
89-
remove_vendor_bundle
90-
warn_bundler_upgrade
91-
warn_bad_binstubs
89+
self.class.remove_vendor_bundle(app_path: self.app_path)
90+
self.class.warn_bundler_upgrade(metadata: @metadata, bundler_version: bundler.version)
91+
self.class.warn_bad_binstubs(app_path: self.app_path, warn_object: self)
9292
@ruby_version = self.class.get_ruby_version(
9393
metadata: @metadata,
9494
report: @report,
@@ -185,10 +185,10 @@ def config_detect
185185
#
186186
# Since `ruby2.5` is not a valid binary name
187187
#
188-
def warn_bad_binstubs
188+
def self.warn_bad_binstubs(app_path: , warn_object: )
189189
check = LanguagePack::Helpers::BinstubCheck.new(
190-
warn_object: self,
191-
app_root_dir: self.app_path,
190+
warn_object: warn_object,
191+
app_root_dir: app_path,
192192
)
193193
check.call
194194
end
@@ -200,12 +200,12 @@ def default_malloc_arena_max?
200200
return false
201201
end
202202

203-
def warn_bundler_upgrade
204-
old_bundler_version = @metadata.read("bundler_version").strip if @metadata.exists?("bundler_version")
203+
def self.warn_bundler_upgrade(metadata: , bundler_version: )
204+
old_bundler_version = metadata.read("bundler_version").strip if metadata.exists?("bundler_version")
205205

206-
if old_bundler_version && old_bundler_version != bundler.version
206+
if old_bundler_version && old_bundler_version != bundler_version
207207
warn(<<~WARNING, inline: true)
208-
Your app was upgraded to bundler #{ bundler.version }.
208+
Your app was upgraded to bundler #{ bundler_version }.
209209
Previously you had a successful deploy with bundler #{ old_bundler_version }.
210210
211211
If you see problems related to the bundler version please refer to:
@@ -681,8 +681,8 @@ def uninstall_binary(path)
681681
# in case there are native ext.
682682
# users should be using `bundle pack` instead.
683683
# https://github.com/heroku/heroku-buildpack-ruby/issues/21
684-
def remove_vendor_bundle
685-
vendor_bundle = self.app_path.join("vendor").join("bundle")
684+
def self.remove_vendor_bundle(app_path: )
685+
vendor_bundle = app_path.join("vendor").join("bundle")
686686
if vendor_bundle.exist?
687687
warn(<<~WARNING)
688688
Removing `vendor/bundle`.

lib/language_pack/test/ruby.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
# methods or over writing methods defined here.
66
class LanguagePack::Ruby
77
def compile
8-
remove_vendor_bundle
9-
warn_bad_binstubs
8+
self.class.remove_vendor_bundle(app_path: self.app_path)
9+
self.class.warn_bundler_upgrade(metadata: @metadata, bundler_version: bundler.version)
10+
self.class.warn_bad_binstubs(app_path: self.app_path, warn_object: self)
1011
@ruby_version = self.class.get_ruby_version(
1112
metadata: @metadata,
1213
report: @report,

0 commit comments

Comments
 (0)