Tony
Tony

Reputation: 19151

Getting started with Ruby Gem Development

Recently I started using a gem called blackbook. The gem has a few issues that I would like to fix. I cloned the git repo and installed the gem locally, hoping I could mess with the source code. When I edit the source code nothing happens, so now I am thinking that I must rebuild the gem every time I make a change.

My question is this: Should I be able to edit the source code of the gem and see results immediately, or should I use the source code as a plugin to my rails app, and then rebuild the gem only when I have made significant progress?

Thank you,

Tony

Upvotes: 3

Views: 1345

Answers (2)

epicgrim
epicgrim

Reputation: 31

I use this rake task to make keeping my gem up to date while working on it. It uses a version number stored in a file at the root named 'VERSION'

desc "Build and install homer gem"
task :update do
  version = File.open('VERSION') { |f| f.read }.to_s
    `gem build homer.gemspec`
    `gem install ./homer-#{version}.gem`
end

and in the gem spec:

s.version = File.open('VERSION') { |f| f.read }.to_s

Upvotes: 2

MarkusQ
MarkusQ

Reputation: 21950

You can mess with the source code of the installed gem to change the behavior of what you have installed. But unless you are playing path games this won't affect the gem itself even if you rebuild.

What I generally do is this:

  • Set up a development area where I can make changes & test them (e.g. run unit tests, spec, etc.)
  • Do most of my work there
  • When I've got something I like, rebuild the gem and try a test install
  • If that works to my satisfaction, push it.

Also, if you are using git hub they should automatically rebuild the gem for you every time you push a commit with an updated gemspec (e.g., you've changed the version number).

Upvotes: 1

Related Questions