-
Notifications
You must be signed in to change notification settings - Fork 9
Bundling
This page is up to date for Rango 0.2.
Bundling is one of the few things where Rango is actually opinionated. The reason is that bundling is real pain in the ass and the only solution which really works is the Bundler.
When you generate new project, you have file called Gemfile
in there. Edit it, and when you are happy with the setup, just run gem bundle
(this RubyGems command comes from the Bundler). It will install all the required gems for you into your gems
directory.
The Bundler create gems/environment.rb
file for you. When you load the file, it will setup your $LOAD_PATH
variable, so you can use Kernel#require
to load your dependencies. Or you can do Bundler.require_env(Rango.environment)
and it will load all the dependencies which are specified for current Rango.environment
or are shared across all the environments. This is the default implementation, check your init.rb
.
NOTE: According to Merb Bundler HOWTO, you shouldn’t use require_as: nil
, because it’s not supported in current Bundler anymore. Use gem "shotgun", only: :bundle
or only(:bundle)
if you don’t want to load it on Bundler.require_env
.
Thanks to Bundler and its disable_rubygems
method you don’t have to use RubyGems in your runtime. Unfortunately RubyGems are loaded by default in Ruby 1.9, so you have to use ruby1.9 --disable-gems
in your shebang. This is the default setup in Rango, so you don’t have to care about it.
task :bundle do exec "gem bundle --cached" end
It might happen that you want to deploy to server where isn’t bundler installed. Solution is easy, just unpack bundler to gems/bundler
and create wrapper script which load this bundler and call Gem::Commands::BundleCommand.new.invoke(*ARGV)
.
#!/usr/bin/env ruby $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "gems/bundler/lib")) require 'rubygems' require 'rubygems/command' require 'bundler' require 'bundler/commands/bundle_command' Gem::Commands::BundleCommand.new.invoke(*ARGV)
Very often you develop an application and a few plugins, gems and other things you want to use in this app.
gem "foo", git: url gem "foo", vendored_at
The second solution is great if you need to put debug statements into your plugin etc, but you must to change it before deployment
- Gem Bundler is the Future
- Using the New Gem Bundler Today
- Using the Rubygems Bundler for Your App