Skip to content

Instantly share code, notes, and snippets.

@adamlogic
Created November 19, 2012 18:26
Show Gist options
  • Save adamlogic/4112527 to your computer and use it in GitHub Desktop.
Save adamlogic/4112527 to your computer and use it in GitHub Desktop.
Extracting to a Gem

Extracting to a gem

Notes for a Columbus Ruby Brigade live-coding talk on 11-19-2012.

  1. Compartmentalize the feature within your project
    • define your API
    • use bundle open and undefined method errors to discover "hooks" for your feature
  2. Create gem skeleton
    • bundle gem gemname
    • add info to gemspec
  3. Write README
    • if you can't clearly explain how to use your gem, it's not worth releasing
  4. Move code from source project to gem
    • start with boilerplate in lib/gemname.rb
    • just get it working – don't worry about lib structure
    • in project Gemfile: gem gemname, :path => '../local_gem_path'
    • restart server, make sure it works
  5. Bring over any JS or other assets
    • subclass Rails::Engine to make gem assets availablet to asset pipeline
  6. Install as a real gem
    • rake install
    • in project Gemfile: gem gemname (remove :path)
  7. Release to rubygems.org
    • rake release
    • create a rubygems account if you haven't before
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment