Ruby bundler: Difference between revisions

From wikinotes
Line 55: Line 55:


# configuring gem build params (for C extensions etc.
# configuring gem build params (for C extensions etc.
# bundle config --global build.{yourpackage} [your gem build params]
# bundle config --{global|local} build.{yourpackage} [your gem build params]
bundle config --global build.snappy --with-opt-dir="/usr/local/opt/snappy"
bundle config --global build.snappy --with-opt-dir="/usr/local/opt/snappy"
bundle config --local build.ffi --enable-system-ffi
</source>
</source>



Revision as of 16:31, 22 October 2021

Commandline Tool to manage a set of ruby gem requirements.
This is similar to python-pip's requirements.txt file.

Documentation

bundler quickstart https://bundler.io/
bundler config options https://bundler.io/v2.2/man/bundle-config.1.html#LIST-OF-AVAILABLE-KEYS
bundler creating gems https://bundler.io/v2.0/guides/creating_gem.html
rubygems creatin gems https://guides.rubygems.org/make-your-own-gem/

Locations

${project}/.bundle/config bundle config (Remembers things like gem path)
~/.bundle/config<?code> global config

Install

gem install bundler

Consuming Gems

Usage

# generate gemfile using 'rubygems.org' as source
bundle init
bundle update --bundler      # update bundler version in Gemfile.lock


# install all gemfile requirements
bundle list                  # list installed
bundle install
bundle install --path .gems  # install to {cwd}/.gems (and remember for future bundle commands)

bundle lock --add-platform x86_64-linux

# install gemfile requirements for specific groups 'cucumber', 'development'
bundle install --without cucumber development

# configuring gem build params (for C extensions etc.
# bundle config --{global|local} build.{yourpackage} [your gem build params]
bundle config --global build.snappy --with-opt-dir="/usr/local/opt/snappy"
bundle config --local build.ffi --enable-system-ffi

Updating Gems

bundle update rails                   # update rails to latest only
bundle update --conservative sidekiq  # update this gem only, ignoring shared dependencies
bundle lock --update=foo              # update 'foo' only to latest in Gemfile.lock
bundle update                         # try to update everything

Gemfiles

See ruby gemfile (outlines gem requirements for project).
Note that if you are writing a gem for rubygems, requirements should be defined in the gemspec file.

Publishing Gems

Gemspec File

Your gemspec file defines requirements, version, author etc.
A gemspec file is required to publish to rubygems.
You can reference your gemspec requirements within a Gemfile by calling the function gemspec.

See https://guides.rubygems.org/specification-reference/

Build/Release

gem build foo.gemspec
gem push foo-0.0.0.gem