Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does Bundler know what environment to use?

Here's probably a very "newbieish" question on Bundler, but I'm wondering how bundle install knows what environment to use or how to set it? Or do I even need to? My problem is that I've grouped my gems (in Gemfile) by environments and when deploying now I only want production gems to be installed.

like image 866
Erik Avatar asked Dec 13 '10 08:12

Erik


People also ask

What does bundler require do?

Bundler. require sets up the load paths and automatically requires every dependency, saving you from having to manually require each one.

What is the difference between bundle and bundler?

The executables bundle & bundler have the same functionality and therefore can be used interchangeably. You can see in the bundler/exe directory that the bundler executable just loads the bundle executable. It seems to me that the bundle command is more commonly used than the bundler command.


Video Answer


1 Answers

At the top of the application.rb file you can see

# If you have a Gemfile, require the gems listed there, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env) if defined?(Bundler)

When Rails is booted, Bundler automatically loads all the dependencies for the :default group and current environment.

Please note that when you run bundle install, Bundler resolves and install dependencies for all the environments, unless you specify a --without option

$ bundle install --without staging development test

In production, you might also want to add the --deployment flag.

More info about bundle install.

like image 102
Simone Carletti Avatar answered Oct 09 '22 04:10

Simone Carletti