Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby gem equivalent of "pip install -e"?

Tags:

ruby

gem

In Python I can install a package from source in "editable" mode using pip install -e. Then I can carry on editing the code, and any changes will be automatically picked by other Python scripts that import library

Is there a comparable workflow for developing Ruby gems? What is the "Ruby way" of using libs as they are being developed rather than, for example, compiling and installing a gem every time I make a change to the source?

like image 315
Nathan Buesgens Avatar asked Nov 11 '14 22:11

Nathan Buesgens


People also ask

What does pip install E does?

pip install -e . This will install the current package in your Python environment in an editable mode. You can keep changing this package at its source directory and your changes will be immediately reflected in your environment.

How do I install a specific version of a ruby gem?

Use `gem install -v` You may already be familiar with gem install , but if you add the -v flag, you can specify the version of the gem to install. Using -v you can specify an exact version or use version comparators.

Does RubyGems come with Ruby?

Ruby comes with RubyGems by default since version 1.9, previous Ruby versions require RubyGems to be installed by hand.

How do I get RubyGems?

Open up the 'Software Center' app from your launcher and type in `RubyGems` without quotes into the application search box at the top right, and press [enter]. RubyGems then can be installed by just clicking on the button labeled 'Install', thats it.


2 Answers

There are two common approaches one might use with bundler:

  1. one executes bundle install --path vendor/bundle and does not run bundle update unless everything is tested.
  2. one tells a bundler to use a local version of the gem:
    • in Gemfile (this is not supported in mymaingem.gemspec due to rubygems maintainence issues): gem 'mycutegem', :git => 'git://github.com/myname/mycutegem', :branch => 'master';
    • in command line: bundle config local.mycutegem /path_to_local_git/mycutegem.

The first approach will download everything into subfolder of your current project (here it’d be vendor/bundle.) Feel free to modify everything there, it’ll be reflected.

The second approach is likely better. You are to clone the gem from github and instruct bundle to use your local clone of the respective git repository. This approach provides you with an ability to publish the changes to your main gem into the repository. As soon as dependent repo is published as well, the up-to-date version will be retrieven by your gem subscribers, assuming they have not instructed their bundlers to use their locals.

Hope this helps.

like image 69
Aleksei Matiushkin Avatar answered Sep 20 '22 08:09

Aleksei Matiushkin


Let's assume you have your gem code residing in a folder (say my_project/mygem/lib). You have some Ruby code in my_project that you want using the mygem code.

What I'd do is add mygem/lib to the $LOAD_PATH global variable in the beginning of said files. Kinda like this:

$LOAD_PATH << File.expand_path('lib', './mygem') # Resolve global paths

require 'a_file' # Would require "mygem/lib/a_file.rb"
like image 40
art-solopov Avatar answered Sep 18 '22 08:09

art-solopov