Class: RBEMigrate::CLI
- Inherits:
-
Object
- Object
- RBEMigrate::CLI
- Defined in:
- lib/rbenv_migrate.rb
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/rbenv_migrate.rb', line 6 def initialize @options = Optimist:: do version "rbenv-migrate #{File.read(File.("../../VERSION", __FILE__)).strip}" self.version "Usage:" " rbenv-migrate OLD_VERSION" "\nOptions:" opt :version, "display version number" opt :help, "display this message" educate_on_error end @old_version = ARGV.first if @old_version.nil? || @old_version == RUBY_VERSION || !Dir["#{ENV['RBENV_ROOT']}/versions/**"].map { |f| File.basename f }.include?(@old_version) Optimist::educate end end |
Instance Method Details
#run ⇒ Object
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 |
# File 'lib/rbenv_migrate.rb', line 26 def run old_gems = gemspecs_for(@old_version).select do |gem| if gem.required_ruby_version =~ Gem::Version.new(RUBY_VERSION) true else $stderr.puts "#{gem.name} #{gem.version} is not compatible with Ruby #{RUBY_VERSION}, skipping." false end end.map(&:name) current_gems = gemspecs_for(RUBY_VERSION).map(&:name) if (gems_to_install = old_gems - current_gems).any? command = Gem::Commands::InstallCommand.new.tap { |c| c. gems_to_install } else puts "Your gems in #{RUBY_VERSION} appear to be up-to-date with #{@old_version}." exit end begin command.execute rescue Gem::SystemExitException # Done nil end end |