Ruby bundle

Recommended for you: Get network issues from WhatsUp Gold. Not end users.
Bundle introduction:
Rails 3 introduced Bundle to manage all of the gem project dependencies, the order can only be executed on a Gemfile containing the root directory, such as the rails 3 project.

On Gemfile and Gemfile.lock
All Ruby project trust package configuration in Gemfile, no longer as before, by require to find. Rails 3 if you need to require a gem package, we must modify the Gemfile file to management.
Gemfile.lock is used to record the machine at present all dependent Ruby Gems and version. It is strongly recommended that the documents into version control, so as to ensure all based on the same working environment.

Bundle command:

# Show all the dependencies
$ bundle show

# Displays the specified position of the gem package
$ bundle show [gemname]

# The project since the gem packet missing inspection system
# Note: if the existence of all project since the packages in the system, it will output: The Gemfile's dependencies are satisfied
$ bundle check

# Installation project relies on all gem package
# Note: this command will attempt to update the system already exists in gem package
$ bundle install

# Install the specified gem package
$ bundle install [gemname]

# Existing updating system project dependencies, and at the same time to update the project file Gemfile.lock
$ bundle update

# The specified gem package information updating system, and at the same time to update the specified item in the Gemfile.lock Bao Xinxi
$ bundle update [gemname]

# Add a new gem to the project package references
$ gem [gemname], [ver]

# You can also specify the package dependency
$ gem [gemname], :require => [dependence_gemname]

# You can even specify the gem package git source
$ gem [gemname], :git => [git_source_url]

# Lock the current environment
# You can use the bundle lock to lock in the current environment, thus not to update the dependencies version by bundle update, to ensure the uniform environment
$ bundle lock

# Release lock
$ bundle unlock

# Packing when environment
# Bundle package will take all the current trust bags were put into the./vendor/cache/ directory, release can be used to ensure consistency package version.
$ bundle package

Automating bundle exec

Bundler is a program for installing the libraries (i.e. gems)that a Ruby application depends on, in a sandbox. By specifying anapplication's dependencies with Bundler developers can guarantee thatonly specific versions of the dependencies are used when the applicationis running on a user's computer, or when deployed to a web server.

Quick instructions

Before I get into the nitty gritty of how it works, here are the quickinstallation instructions:
$ curl -L > ~/
$ echo "[ -f ~/ ] && source ~/" >> ~/.bashrc
Read more on the GitHub page.

How bundler-exec works

Once bundler-exec is configured, it replaces a bunch of common Rubycommands (e.g. rake, ruby, rails, rspec) with a shell functionthat will:
Check whether your current directory is within a bundled project (itchecks for a Gemfile in your current directory, or one of itsparents), andRun the command you entered, prefixing it with bundle exec ifappropriate. It does this with the magic of shell aliases (and therefore only workswith Bourne style shells, or shells that support the alias command).Browse the code on GitHub; it's very simple stuff. The full listof commands that it looks after for you is currently:
capcapifycucumberherokurackuprailsrakerspecrubyshotgunspecsporkthinunicornunicorn_rails You can easily override that list by setting BUNDLED_COMMANDS in your~/.bashrc file before ~/ gets loaded, like this:
[ -f ~/ ] && source ~/
If you need to add commands that are in common use, please fork theproject, add them to the script, and send me a pull request. Cheers!
To check whether bundler-exec is configured, check what your shellwill do if you run Ruby. It should tell you that Ruby has been aliased,like this:
$ type ruby
ruby is aliased to `run-with-bundler ruby'

What can go wrong if you forget bundle exec?

Remembering to run bundle exec is a pain, can be easy to forget, andno end of subtle bugs can occur if you forget it.
Imagine that your project requires version 1.0.0 of a gem, but you'vegot both 1.0.0 and 1.0.1 installed. It all goes south like this:
Your shell will find the command that shipped with 1.0.1, and run it.The command will load your application code, which callsBundler.require or Bundler.setup.Bundler (quite rightly) complains when it tries to load 1.0.0 andfinds that 1.0.1 is "already activated").
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Adolph at February 25, 2014 - 4:57 AM