3 Bundler & Gems Flashcards
What is a gem?
A gem is a packaged Ruby application or library. It has a name and a version.
A gem’s functionality can be added and used in your projects.
RubyGems is the name of the project that developed the gem packaging system and
the gem command. You can get RubyGems from the main http://rubygems.org repository.
RubyGems is now part of the standard library in Ruby versions 1.9 and later.
What is Bundler? How do you install it?
Bundler— a gem for bundling gems
Bundler makes sure Ruby applications run the same code on every machine.
It does this by managing the gems the application depends on. Given a list of gems, it can
automatically download and install them, as well as any others the listed gems need.
Before installing gems, Bundler checks the versions of every one to make sure they are
compatible and can all be loaded at the same time. After the gems have been installed, Bundler
can help you update some or all of them when new versions become available. Finally, it records
the exact versions that have been installed so that others can install the exact same ones.
Installing Bundler
$ gem install bundler
How do you check/update the Bundler version?
The Gemfile.lock file is where Bundler records the
exact versions that were installed. This way, when
the same library/project is loaded on another
machine, bundle install will look at
the Gemfile.lock and install the exact same
versions, rather than just using the Gemfile and
installing the most recent versions.
What is a Gemfile?
Gemfile—a format for describing gem dependencies for Ruby programs
What is the difference between a Gemfile and
Gemfile.lock?
Gemfile has libraries that you use in your project. And Gemfile.lock has records about versions that Bundler installed
Do we need to specify the Ruby version in a Gemfile?
Why or why not?
Not a ruby version, but versions of all gems
Do we need to commit the Gemfile.lock? Why or why
not?
Yes, we do. Because, this file is used by bundler when user wants to install all used in project gems
What is the difference between bundle add
GEM_NAME and gem install GEM_NAME?
$ bundle add
This command adds the named gem to the Gemfile and runs bundle install.
$ bundle install
* If the library is already downloaded, it will simply fetch it from installed.
* If the library is not downloaded yet, it will download it from the source.
Which sources could be used to push/pull gems in
your Gemfile? How do you specify this in a Gemfile?
- RubyGems.org
Rubygems.org is the Ruby community’s gem-hosting service. The purpose of this project is to provide
a better API for dealing with gems.
To install a gem published on rubygems.org, you have to declare it as a “source” in your Gemfile. - Gems published on the Git remote platform (Github, Gitlab, etc.)
To install gems published on Git, you have to specify the url in Gemfile.
If necessary, you can specify the branch, ref, or tag from the Git repository.
How is semantic versioning applied to a Gemfile?
(What are patch, minor, and major versions?)
Given a version number MAJOR.MINOR.PATCH (example: 1.3.15), increment the:
* MAJOR version when you make incompatible changes
* MINOR version when you add functionality in a backwards-compatible manner
* PATCH version when you make backwards-compatible bug fixes
What does the line
gem rubocop, ~> ‘1.0’ mean in a Gemfile?
Most of the version specifiers, like >= 1.0, are self-explanatory.
The specifier ~> has a special meaning and is best shown using an example:
* ~> 2.0.3 is identical to >= 2.0.3 and < 2.1
* ~> 2.1 is identical to >= 2.1 and < 3.0
* ~> 2.2.beta will match pre-release versions like 2.2.beta.12
Do we need to specify the gem versions in a Gemfile?
Why or why not?
Yes. This allows you to install the most recent version that you need and perform updates later without Gemfile
changes.
How does bundle update work?
Update the gems specified (for all gems, if –all flag is used), ignoring the previously installed gems
specified in Gemfile.lock. Use bundle update to explicitly update the version of a gem.
How do you list outdated gems in your Gemfile?
(Gems that could potentially be updated)
Outdated lists the names and versions of gems that have a newer version available in the given source.
Calling outdated with [GEM [GEM]] will only check for newer versions of the given gems. Pre-release gems
are ignored by default.
Can the Gemfile.lock be edited?
DON’T make changes in Gemfile.lock manually
Manual changes in Gemfile.lock can make a mess in terms of gem versions for other developers.