Posted over 7 years ago. Visible to the public.

Gems, bundler, rbenv [1d]

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 Archive 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 Archive .
  • 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

  • Look at Faker's GitHub repository Archive .
  • Browse through the code and get an idea how it works (you don't have to read or understand it completely). You can either use GitHub's code browser or clone the repository and open it in your code editor.
  • Look at Faker's .gemspec file in the project's root directory. Understand what it says and how it feeds the faker page on rubygems.org Archive .
Avatar
Henning Koch
Last edit
3 months ago
Michael Leimst├Ądtner
About this deck
We are makandra and do test-driven, agile Ruby on Rails software development.
Posted by Henning Koch to makandra Curriculum (2015-07-07 16:59)