Skip to content

Instantly share code, notes, and snippets.

@sanemat
Last active September 10, 2016 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sanemat/af560315b1e4770dc527d4cfbf8d944a to your computer and use it in GitHub Desktop.
Save sanemat/af560315b1e4770dc527d4cfbf8d944a to your computer and use it in GitHub Desktop.
How to be friends with bundler http://bit.ly/rubykaigi2016bundler

How to be friends with bundler

sanemat {AT} tachikoma.io

What is "be friends with bundler"???

  • Slide: EN
  • Talk: JA

Money Forward, Inc.

Challenge 1: ruby DSL

ruby "2.3.0"
source "https://rubygems.org"
gem "ecdsa"

In Gemfile.

  • Error out if the ruby version doesn't match
$ bundle
Your Ruby version is 2.3.1, but your Gemfile specified 2.3.0
(exit code: 0)

You may use this with heroku app.

History

Bundler v1.2.0 (Aug 30, 2012)

  • add ruby to DSL, to specify version of ruby

bundle update

  • Tachikoma is a gem which helps bundle update and sends pull request.
  • Tachikoma.io is Bundle Update as a Service.
  • I'm a founder of both tachikoma gem and tachikoma.io :)

I use "one" ruby version, and run bundle update with Gemfile which has ruby "2.3.0", ruby "2.3.1", ...

How to be friends with bundler

Run this before bundle update.

sh(*['ruby', '-i', '-pe', '$_.gsub! /^ruby/, "#ruby"', 'Gemfile'])

:-)

https://github.com/sanemat/tachikoma/blob/391307db508f29cde46957edf9baba38c7a2933e/lib/tachikoma/application.rb#L81

Challenge 2: BUNDLED WITH

GEM
  remote: https://rubygems.org/
  specs:
    ecdsa (1.2.0)

PLATFORMS
  ruby

DEPENDENCIES
  ecdsa

BUNDLED WITH
   1.12.0

You can store bundler version in Gemfile.lock after bundle update.

History

Bundler v1.10.0 (2015-05-28)

  • Bundler v1.9 always removes BUNDLED WITH section.
  • Bundler v1.10 always adds BUNDLED WITH section.

I use one bundler :(

How to be friends with bundler

https://github.com/packsaddle/ruby-restore_bundled_with

$ restore-bundled-with

This restores BUNDLED WITH section from git repository.

Challenge 3: RUBY VERSION

GEM
  remote: https://rubygems.org/
  specs:
    ecdsa (1.2.0)

PLATFORMS
  ruby

DEPENDENCIES
  ecdsa

RUBY VERSION
   ruby 2.3.1p112

BUNDLED WITH
   1.12.5
  • If you write ruby "2.3.1", then lock ruby version in Gemfile.lock.
  • This allows you can write ruby "~> 2.3.0".
  • Cool!

History

Bundler v1.12.0 (2016-04-28)

  • bundle update with v1.12.0, always add RUBY VERSION section.
  • bundle update with v1.12.5, if creating Gemfile.lock, then adding RUBY VERSION, if not then don't write RUBY VERSION in Gemfile.lock.

I use one ruby :)

How to be friends with bundler

https://github.com/packsaddle/ruby-restore_ruby_version

$ restore-ruby-version

This restores RUBY VERSION section from git repository.

This does not publish yet ;(

Bundler v2.0

Future :)

  • Gemfile -> gems.rb
  • Gemfile.lock -> gems.locked

How to be friends with bundler

if File.exist?('Gemfile')
  @bundler_key_file = 'Gemfile'
  @bundler_lock_file = 'Gemfile.lock'
elsif File.exist?('gems.rb')
  @bundler_key_file = 'gems.rb'
  @bundler_lock_file = 'gems.locked'
else
  @bundler_key_file = 'Gemfile'
  @bundler_lock_file = 'Gemfile.lock'
end

oh

https://github.com/sanemat/tachikoma/blob/391307db508f29cde46957edf9baba38c7a2933e/lib/tachikoma/application.rb#L85-L94

Bundler v1.13

Bundler v1.13.0 (2016-09-09)

@sanemat And mention bundle patch? Now in prerelease version of Bundler. https://twitter.com/JuanitoFatas/status/774138984729448448

I don't battle be friends with bundler v1.13 yet, :)

To be continued...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment