Groups in a Gemfile in Rails 3

Groups in a Gemfile in Rails 3?

From http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/:

Specifying groups allows you to do two things. First, you can install
the gems in your Gemfile, minus specific groups. For instance, Rails
puts mysql and pg in a database group so that if you’re just working
on ActionPack, you can bundle install --without db and run the
ActionPack tests without having to worry about getting the gems
installed.

Second, you can list specific groups to autorequire using
Bundler.require. By default, Bundler.require requires all the gems in
the default group (which is all the gems that have no explicit group).
You can also say Bundler.require(:default, :another_group) to require
specific groups.

Gems groups in the Gemfile for rails

If you are using the exact gems for all of the environments, you don't need to specify it in group.

You can find more about bundler groups here :

http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

http://bundler.io/v1.3/groups.html

Gemfile group is used for?

It means you don't need this gem in production. But if you want use test or development mode, you need it.

You can install without some group with bundler like :

bundle install --without= development test

In this case all gems in development and test group are not installed and not required.

Bundler - updating gems in a particular group

Yes, with

$ bundle update --conservative --group test development

Bundler’s --conservative option is key, because it prevents updates in any "Production" gem that is also a dependency of a "Test" or "Development" gem.

How is the :assets group in rails 3.1 handled by bundler?

The code that handles :assets group placed in config\application.rb. In rails 3.1 it is:

if defined?(Bundler)
# If you precompile assets before deploying to production, use this line
Bundler.require *Rails.groups(:assets => %w(development test))
# If you want your assets lazily compiled in production, use this line
# Bundler.require(:default, :assets, Rails.env)
end

how to install production group in the Gemfile

in your .bundle/config file you probably have this line:

BUNDLE_WITHOUT: production

Just delete this line, and the bundle install will also install the gems from the production group



Related Topics



Leave a reply



Submit