Class: Stable::Commands::UpgradeRuby

Inherits:
Object
  • Object
show all
Defined in:
lib/stable/commands/upgrade_ruby.rb

Overview

Command for upgrading/downgrading Ruby versions for applications

Instance Method Summary collapse

Constructor Details

#initialize(name, version) ⇒ UpgradeRuby

Returns a new instance of UpgradeRuby.



9
10
11
12
# File 'lib/stable/commands/upgrade_ruby.rb', line 9

def initialize(name, version)
  @name = name
  @version = version
end

Instance Method Details

#callObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/stable/commands/upgrade_ruby.rb', line 14

def call
  app = Services::AppRegistry.find(@name)
  unless app
    puts "No app named #{@name}"
    return
  end

  current_version = app[:ruby] || RUBY_VERSION

  puts "#{action(current_version, @version)} #{@name} from Ruby #{current_version} to #{@version}..."
  puts ''

  # Install the target Ruby version if needed
  platform = Stable::Utils::Platform.current

  if platform == :windows
    puts '⚠️  Windows detected - Ruby version managers work differently on Windows'
    puts "   Please manually install Ruby #{@version} using RubyInstaller or your preferred method"
    puts '   Recommended: https://rubyinstaller.org/'
    puts '   Then update your PATH to use the new Ruby version'
    puts ''
    puts "After installing Ruby #{@version}, update the app configuration manually:"
    puts "   - Edit .ruby-version file to contain: #{@version}"
    puts '   - Run: bundle install (in the app directory)'
    return
  end

  if Stable::Services::Ruby.rvm_available?
    puts "Ensuring Ruby #{@version} is available..."
    system("bash -lc 'rvm install #{@version}'") unless ENV['STABLE_TEST_MODE']
  elsif Stable::Services::Ruby.rbenv_available?
    puts "Ensuring Ruby #{@version} is available..."
    system("rbenv install #{@version}") unless ENV['STABLE_TEST_MODE']
  else
    puts '❌ No supported Ruby version manager found'
    puts '   On macOS/Linux, install RVM (https://rvm.io/) or rbenv (https://github.com/rbenv/rbenv)'
    puts '   On Windows, use RubyInstaller (https://rubyinstaller.org/)'
    return
  end

  # Clean, simple approach: Remove current Ruby environment and install new one fresh
  puts "🔄 Upgrading #{@name} from Ruby #{current_version} to #{@version}..."

  # 1. Remove current Ruby version/gemset (like destroy command)
  cleanup_rvm_gemset(app)

  # 2. Install new Ruby version fresh (like app creator)
  setup_new_ruby_version(app, @version)

  puts ''
  puts "#{@name} #{past_tense_action(action(current_version, @version))} to Ruby #{@version}!"
  puts "   Old gemset cleared, fresh #{@version}@#{@name} gemset created with gems"
  puts ''
  puts "Start with: stable start #{@name}"
end