Ever used a rubygem, found a bug, and just wanted to quickly bust out the big guns and fix it quickly?
gem command doesn’t come packed with a way to find the original source repository for a gem. At best, most gems at least come bundled with the complete source, tests and documentation. Some gems don’t. Fair enough, since having access to the complete source via the gem still doesn’t allow you to fix a bug and share it with the world.
For that you access to the repo, a quick way to fork it, and a post-github way to share a gem version from yours truly.
github gem and gemcutter are the modern day tools of master hackermanship.
Instant forking fun
Let’s say you find a bug in a gem, say
rails, and you want to go to town on its source.
You know the gem is called
rails but you’ve no idea what the github repo is called. Never fear.
$ gem sources -a http://gemcutter.org $ sudo gem install github $ gh clone --search rails Select a repository to clone: 1. rails/rails # Ruby on Rails 2. technoweenie/restful-authentication # Generates common user ... 3. justinfrench/formtastic # A Rails form builder plugin ... ?
1 and you’ll get a clone of
Alternately, if you want a fork or you know the exact user/repo already:
$ gh clone rails/rails
Now, fork your own version:
$ cd rails $ gh fork
You now have your own fork. The
origin remote also now points to your fork rather than the
$ git remote show origin * remote origin Fetch URL: firstname.lastname@example.org:drnic/rails.git Push URL: email@example.com:drnic/rails.git
So, make your changes, push them. Send a pull request or github issue or lighthouse ticket or what have you.
Want to get to the github project home page for your fork?
$ gh home
Instant gem sharing
Let’s say you patched the
rails gem itself but you want to share your changes via your own gem.
In the olden days, github did this for you. Now you use gemcutter, and a little manual effort to do your own renaming.
First, install the gems locally, use them, and make sure all is good.
For rails, you install the edge gems (3.0.pre) with:
$ rake install
You can’t see ‘rake install’ in the
rake -T list (hence my patch), but I think the following expression displays all tasks regardless if they have a description or not:
$ rake -P | grep "^r"
Rails is composed of several gems, unlike most projects that are distributed as a single gem. Here we want to share our commit within a new
drnic-rails gem, but not touch the others.
railties/rails.gemspec file from:
Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = 'rails' s.version = '3.0.pre' ...
and give your personal gem a new name:
Gem::Specification.new do |s| s.platform = Gem::Platform::RUBY s.name = 'drnic-rails' s.version = '3.0.pre'
To build and distribute the new gem:
$ gem build railties/rails.gemspec $ sudo gem install gemcutter $ gem push drnic-rails-3.0.pre.gem Pushing gem to Gemcutter... Successfully registered gem: drnic-rails (3.0.pre)
Follow any first-time gemcutter instructions and SUCCESS! Now I have my own drnic-rails gem.
To find, clone, and fork any rubygem that is hosted on github:
$ sudo gem install drnic-github $ gh clone --search rails $ gh fork
To personalise the gem and share it on gemcutter:
> edit the project.gemspec to have a unique name, e.g. yourname-project $ gem build project.gemspec $ sudo gem install gemcutter $ gem push yourname-project-1.0.0.gem
I think this makes it much easier, faster and more fun to hack other people’s stuff.
- Migrating project websites to github pages with sake tasks, new websites with jekyll_generator Its almost Christmas time and that means presents. It...
- newgem 1.0.0 all thanks to Cucumber The New Gem Generator (newgem) was exciting, moderately revolutionary, and...
- My attempt at sake task management I’ve used sake intermittently in my workflow. It competes...
- [ANN] Generating new gems for graceful goodliness I don’t like you . You don’t share code....