Skip to content

Instantly share code, notes, and snippets.

@woodie
Created October 27, 2009 05: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 woodie/219335 to your computer and use it in GitHub Desktop.
Save woodie/219335 to your computer and use it in GitHub Desktop.
bundle and jar up from within ruby
require 'rubygems'
require 'fileutils'
require 'zip/zip'
require 'zip/zipfilesystem'
require 'rubygems/command_manager'
# ...
def gem_bundler(args)
Gem.platforms = [Gem::Platform::RUBY,
Gem::Platform.new('universal-java')]
Gem.configuration = Gem::ConfigFile.new(args.unshift('bundle'))
puts "=> Bundling gems"
begin
Gem::CommandManager.instance.run(Gem.configuration.args)
rescue Gem::SystemExitException => e
exit e.exit_code unless e.exit_code == 0
end
if !args.include?('--update') and File.exists?(app.gems_jar) and
File.stat(app.gems_jar).mtime > File.stat(app.gemfile).mtime
return
end
gem_files = Dir["#{app.gems_dir}/**/**"]
FileUtils.rm app.gems_jar, :force => true # blow away the old jar
puts "=> Installing gems"
Zip::ZipFile.open(app.gems_jar, 'w') do |jar|
gem_files.reject {|f| f == app.gems_jar}.each do |file|
jar.add(file.sub("#{app.gems_dir}/",''), file)
end
end
end
# ...
# Critical default settings:
disable_system_gems
disable_rubygems
bundle_path ".gems/bundler_gems"
# List gems to bundle here:
#gem "rack", "1.0.0"
gem "dm-appengine"
gem "sinatra"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment