Dror
Dror

Reputation: 13051

How to efficiently fork a gem

I found a useful gem (here's the link if you're curious). I installed it using sudo gem install json_resume. Now it resides on /Library/Ruby/Gems/2.0.0/gems/json_resume-1.0.4/ (Mac OS). However, I needed to change some of its elements. So far I changed them in the /Library directly. This is obviously not the best way.

I'd like to fork the repository and install my version. How do I do it? I found this answer, but I'm too new to Ruby and failed to understand what to do.

More details: After installing the gem I found the following script /usr/local/bin/json_resume:

#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby


#!/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby
#
# This file was generated by RubyGems.
#
# The application 'json_resume' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require 'rubygems'

version = ">= 0"

if ARGV.first
  str = ARGV.first
  str = str.dup.force_encoding("BINARY") if str.respond_to? :force_encoding
  if str =~ /\A_(.*)_\z/
    version = $1
    ARGV.shift
  end
end

gem 'json_resume', version
load Gem.bin_path('json_resume', 'json_resume', version)

It seems like it calls the gem installed in /Library/Ruby/Gems/2.0.0/gems/json_resume-1.0.4/. I failed to point it to the forked version of mine.

Upvotes: 1

Views: 1699

Answers (1)

user229044
user229044

Reputation: 239312

You should definitely not be modifying the version which is installed system-wide.

Instead, you should:

  1. Clone the repository on Github
  2. Checkout your copy of the source code locally

    $ cd /home/my_user
    $ git clone [email protected]:/.../my_forked_gem
    
  3. Use the local copy of the gem's source code in your consuming project's Gemfile instead of the Rubygems-hosted gem:

    gem 'my_forked_gem', path: '/home/my_user/my_forked_gem'
    
  4. Modify your local copy in ~/my_forked_gem, and push to your forked Github repo

  5. Issue pull requests against the original project for any features you think are worthy of inclusion in the original gem

Upvotes: 8

Related Questions