Skip to content

Instantly share code, notes, and snippets.

@ridiculous
Created August 10, 2017 23:31
Show Gist options
  • Save ridiculous/0af33819ade88c38b7f45e081e61a20d to your computer and use it in GitHub Desktop.
Save ridiculous/0af33819ade88c38b7f45e081e61a20d to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Installs the latest version of a gem to the "vendor/gems" directory, which can be referenced from the Gemfile
# Expects the gem to be in the "vendor/gems" directory
#
# @usage Sudo is used because it writes to a directories in "vendor/gems"
#
# sudo ruby script/unpack <gem>
#
require 'pathname'
name = ARGV.pop || fail(ArgumentError, 'Please pass a gem name')
app_root = Pathname.new(File.expand_path("../..", __FILE__))
gem_path = app_root.join("vendor/gems/#{name}-*.gem")
gem = Dir[gem_path].last
gem || fail(ArgumentError, "Failed to find gem with name #{name} in #{gem_path}")
if File.file?(gem)
gem = Pathname.new(gem)
puts "Unpacking #{gem.basename}"
$stdout.flush
gem = app_root.join("vendor/gems/#{gem.basename}")
`gem unpack #{gem} --target #{app_root.join("vendor/gems")}`
`cp -r #{gem.sub('.gem', '/.')} #{app_root.join("vendor/gems/#{name}")}`
`rm -R #{gem.sub('.gem', '/')}`
else
fail "#{gem} -- does not exist"
end
puts 'Done'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment