3 Bundler & Gems Flashcards

1
Q

What is a gem?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Bundler? How do you install it?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you check/update the Bundler version?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a Gemfile?

A

Gemfile—a format for describing gem dependencies for Ruby programs

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the difference between a Gemfile and
Gemfile.lock?

A

Gemfile has libraries that you use in your project. And Gemfile.lock has records about versions that Bundler installed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Do we need to specify the Ruby version in a Gemfile?
Why or why not?

A

Not a ruby version, but versions of all gems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Do we need to commit the Gemfile.lock? Why or why
not?

A

Yes, we do. Because, this file is used by bundler when user wants to install all used in project gems

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between bundle add
GEM_NAME and gem install GEM_NAME?

A

$ 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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which sources could be used to push/pull gems in
your Gemfile? How do you specify this in a Gemfile?

A
  1. 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.
  2. 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How is semantic versioning applied to a Gemfile?
(What are patch, minor, and major versions?)

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does the line
gem rubocop, ~> ‘1.0’ mean in a Gemfile?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Do we need to specify the gem versions in a Gemfile?
Why or why not?

A

Yes. This allows you to install the most recent version that you need and perform updates later without Gemfile
changes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does bundle update work?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How do you list outdated gems in your Gemfile?
(Gems that could potentially be updated)

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Can the Gemfile.lock be edited?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you find the dependencies (other gems) of
the gem listed in a Gemfile?

A

In Gemfile, gems should be in alphabetical order. Find it’s dependencies in Gemfile.lock

17
Q

What is ’bundle exec’?

A

bundle exec is a Bundler command to execute a script in the context of the current bundle (the one from your directory’s Gemfile).

18
Q

Why do we need groups in a Gemfile?

A

The modern Rails app has a lot of dependencies, but quite a few of them are only used to speed up
the development process or provide tools for debugging and testing. None of them are needed when running
the app in production. Put all these dependencies in a “development” group.
group :development do
gem’web-console’
gem’spring’
end