R.M.
R.M.

Reputation: 3652

How to replace a Ruby gem with code from a local source directory

I've been using a Ruby package which I installed as a gem. Now I'd like to modify the code, to try my hand at fixing bugs/adding features. I can download the source for the package from GitHub, however, I'm not sure what to do next.

Is there an easy way I can replace a particular gem with code from a local source directory? Ideally, the process would be simple enough that I'd be able to continuously update as I modify the code.

Also, this package is used as a dependency for other gems, and ideally the other packages which use this gem would then use the updated version. (As the program I'm ultimately running is from one of those other gems.) Is there a way to do the install without also installing those other packages from source?

(This would be on Linux, if it makes things easier.)

Upvotes: 2

Views: 1557

Answers (2)

Stewart
Stewart

Reputation: 3161

Assuming your using bundler you can set this in your Gemfile. If your not sure your using bundler look in the root of your project. There should be one file called Gemfile with no extension. The presence of this file will generally indicate that the project's author is using bundler. All changes described below should be made inside that file.

The :path and :git keys in the gem hashmap can be used to point rubygems to different locations. When I am using :path I will have two different ruby projects. The first project is the active project. The project that I am currently working on. This project requires the gem in question that I need to update. The second project will the the checked out source code of the gem I wish to change. With these two projects setup I can edit the Gemfile of the first project and point it at the second project. This is done using :path.

# The Gemfile of the first project
gem 'the_gem_in_question', :path => '/the/path/to/the/second/project'

Upvotes: 2

Ho Man
Ho Man

Reputation: 2345

There are two ways to modify these files and have the changes show up.

One is using the Gemfile to define a path. For example if you wanted the redis gem locally, you can git clone [email protected]:redis/redis-rb.git then as Stewart pointed above, put it into your Gemfile this line gem 'redis', :path => './pathtoredis/redis' instead of gem 'redis'

Another way, which is a little quicker but harder to track changes and stuff is to just gem open redis to open it in a text editor.

Upvotes: 0

Related Questions