Skip to content

Instantly share code, notes, and snippets.

@itspriddle
Created November 27, 2012 16:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itspriddle/4155109 to your computer and use it in GitHub Desktop.
Save itspriddle/4155109 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
#
# Usage: rebundle gem_name
#
# The script will remove the gem dependency tree from the lockfile and bundle.
LOCKFILE_NAME = "Gemfile.lock"
lockfile = File.readlines(LOCKFILE_NAME)
# Finds where the gem dependency tree begins
def beginning(gem_name, lockfile)
lockfile.each_with_index do |line, index|
if line.include?("specs:") && lockfile[index+1].include?(gem_name)
# traverse back until GIT
until (prev_line ||= "").include?("GIT")
prev_line = lockfile[index = index.pred]
end
return index
end
end
false
end
# Finds where the gem dependency tree ends
def ending(beginning, lockfile)
lockfile.drop(beginning).each_with_index do |line, index|
return index if line == "\n"
end
false
end
if b = beginning(ARGV[0], lockfile)
e = ending(b, lockfile) + b
lockfile.slice!(b..e)
# Writes the lockfile without the gem dependency tree
File.write(LOCKFILE_NAME, lockfile.join)
end
# Ready to bundle
IO.popen('bundle') { |f| puts f.read }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment