Skip to content

Instantly share code, notes, and snippets.

@rsierra
Last active September 28, 2015 06:38
Show Gist options
  • Save rsierra/1400264 to your computer and use it in GitHub Desktop.
Save rsierra/1400264 to your computer and use it in GitHub Desktop.
Script para generar el Gemfile de bundler a partir de un 'gem list'
#!/usr/bin/env ruby
# So you want to start developing an already "woking" project. No
# bundle, config.gem's not present or messing up dependencies. Fear
# not!
# Do a "gem list" wherever the project is already working
# (production?, some colleage machine?). Make a file with this format:
#
# chronic (0.2.3)
# colored (1.1)
# daemons (1.0.10)
# fastercsv (1.4.0)
# fastthread (1.0.7)
# feed-normalizer (1.5.1)
# feedtools (0.2.26)
# ferret (0.11.4)
# gcnovus-avatar (0.0.7)
# gem_plugin (0.2.3)
# gettext (1.93.0, 1.9.0)
#
# Run "rawclone_bundle yourgemsfile" on your machine to create Gemfile for bundler.
SOURCES = ["http://rubygems.org", "http://gems.github.com"]
GEMFILE = "Gemfile"
RAILSGEMS = ["actionmailer", "actionpack", "activerecord", "activeresource", "activesupport"]
gems = {}
def add_oldest_gem(gems, name, version)
name = 'rails' if RAILSGEMS.include? name
if gems.has_key? name
gems[name] = [version] if version < gems[name].first
else
gems[name] = [version]
end
end
def add_gem(gems, name, version)
name = 'rails' if RAILSGEMS.include? name
gems[name] = [] if gems[name].nil?
gems[name] << version unless gems[name].include? version
end
def write_gem(file, name, versions)
file.puts "# Duplicate gem" if versions.count > 1
versions.each do |version|
file.puts "gem '#{name}', '#{version}'"
end
end
unless ARGV[0].nil?
File.open(ARGV[0],'r').each do |line|
line.gsub!(/\(|\)|,/,'')
name = line.split[0]
line.split[1..-1].each do |version|
add_gem gems,name,version
end
end
File.open(GEMFILE, 'w') do |file|
SOURCES.each { |source| file.puts "source '#{source}'" }
file.puts ""
write_gem file, 'rails', gems['rails']
gems.delete('rails')
file.puts ""
gems.each do |key,value|
write_gem file, key, value
end
end
puts "#{GEMFILE} created"
puts "Now check the file for duplicated gems, clean it and run bundle install"
else
puts "Make a Gemfile for bundler from a Gemlist"
puts "Usage: rawclone_bundler file"
puts "Then, you can run bundle isntall"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment