125 Gems, bundler, rbenv [1d]

Updated . Posted . Visible to the public.

makandra is responsible for maintaining about 75 Ruby projects. These projects use a large number of different versions for Ruby, Rails and many gems. To be able to switch between projects easily, we must control every dependency our applications has.

Goals

  • Understand what a gem is
  • Learn how to install a gem
  • Be able to look into gem code
    • locally
    • on GitHub
  • Learn about Bundler
    • Why is it necessary:
      • Managing versions and dependencies
      • Defining a consistent project environment
    • What is the difference between bundle install and bundle update?
    • What does bundle exec do, why is it necessary?
    • What does the file Gemfile.lock do?
  • rbenv
    • Understand why we need rbenv

Resources

Exercises

Working with rbenv

  • Use rbenv to install an older Ruby version, like 2.5.
  • In an earlier lesson you built a searchable address book.
  • Freeze that program's Ruby version to 2.5 by adding an .ruby-version file.
  • Open a new terminal and check your default Ruby version (ruby -v)
  • Now cd into the directory for the address book app. Observe how rbenv has automatically switched to the Ruby version from your .ruby-version.
  • Commit and push your changes.

Tip

RubyMine seems to only parse the .ruby-version file when you're opening a project for the first time. When you're changing the .ruby-version of an existing project, RubyMine may not automatically detect that you want to use another version.

If this is the case, go to File / Settings / Languages & Frameworks / Ruby SDK & Gems and select the new Ruby version.

Working with Bundler

  • In an earlier lesson you built a searchable address book.
  • Add a Gemfile to that repository and let bundler create a Gemfile.lock. It won't have any dependencies at first.
  • Commit the Gemfile and Gemfile.lock.
  • Use Bundler to install the Faker Show archive.org snapshot gem in the exact version 2.10.0.
  • Observe the changes Bundler made to your Gemfile.lock. Compare these changes to faker's dependencies on rubygems.org Show archive.org snapshot .
  • In your program, use Faker to create 100 contacts with fake data.
  • Commit your changes.
  • Use Bundler to upgrade Faker to the latest possible version that runs with Ruby 2.5.
  • Observe the changes Bundler made to your Gemfile.lock during the upgrade.
  • Commit and push your changes.

How gems are made

Henning Koch
Last edit
Felix Eschey
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra Curriculum (2015-07-07 14:59)