Skip to content

Instantly share code, notes, and snippets.

@neonichu
Last active March 1, 2020 07:13
Show Gist options
  • Save neonichu/82849462714c5572eb2e to your computer and use it in GitHub Desktop.
Save neonichu/82849462714c5572eb2e to your computer and use it in GitHub Desktop.
A simple CocoaPods version manager.
#!/usr/bin/env ruby
require 'rubygems'
require 'yaml'
def install_gem(name, version)
require 'rubygems/commands/install_command'
cmd = Gem::Commands::InstallCommand.new
cmd.handle_options [name, '--version', version]
begin
cmd.execute
rescue Gem::SystemExitException => e
e.exit_code == 0
end
end
if File.exist?('Podfile.lock')
lockfile = YAML.load(File.read('Podfile.lock'))
version = lockfile['COCOAPODS']
begin
gem 'cocoapods', "=#{version}"
rescue Gem::LoadError
puts "Auto-installing CocoaPods #{version}"
exit(1) unless install_gem('cocoapods', version)
begin
gem 'cocoapods', "=#{version}"
rescue Gem::LoadError => message
STDERR.puts message
exit(1)
end
end
end
require 'cocoapods'
Pod::Command.run(ARGV)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment