1

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.

Community
  • 1
  • 1
Dror
  • 12,174
  • 21
  • 90
  • 160

1 Answers1

8

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 git@github.com:/.../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

user229044
  • 232,980
  • 40
  • 330
  • 338
  • Will step 3 above overwrite the gem's version which was already installed? Or, do I have to manually remove it first? – Dror Jan 09 '17 at 06:05
  • No, you don't have to uninstall anything. That's the entire point of using Bundler/Gemfile - it lets you have separate versions of the same gem installed for different apps. – user229044 Jan 09 '17 at 11:51
  • So how do I know/choose which version is (to be) used? – Dror Jan 09 '17 at 13:28
  • @Dror I'm not sure what you mean. If you use `path: /path/to/your/gem`, that's obviously using the locally checked out source. If you don't use `path: /path/to/your/gem` that's using the system-wide one. – user229044 Jan 09 '17 at 13:45
  • So I can run step (3) above without or with the last part (`path: /path/to/your/gem`) to use the remote/official version or the local one, respectively? – Dror Jan 09 '17 at 13:53
  • I'm afraid this is not helpful. Step (3) doesn't install my modified fork. I don't understand how can I use my modified fork. – Dror Jan 09 '17 at 19:13
  • For reference: here's my fork https://github.com/drorata/json_resume and this is my `Gemfile` https://github.com/drorata/json_resume/blob/master/Gemfile – Dror Jan 09 '17 at 19:15
  • @Dror You need to edit your Gemfile in your **consuming** project, not in the Gem. – user229044 Jan 10 '17 at 01:45
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/132743/discussion-between-dror-and-meagar). – Dror Jan 10 '17 at 04:44