Skip to content

Instantly share code, notes, and snippets.

@fabiokr
Created November 7, 2012 15:26
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 fabiokr/4032230 to your computer and use it in GitHub Desktop.
Save fabiokr/4032230 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
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