Code Resue for Ruby Gems, Plugins, Git

We see several broad areas where we want code reuse.

Public Protected Private
Origin RubyForge, GitHub,
RailApp, etc.
Org Internal:
shared by projects
Org Internal:
specific to one project
Examples Rails
Org rails base app
Org business rules
Org stylesheets
Rails app "Foo"
Gems for "Foo"
Layouts for "Foo"

  • Install on the system using gem install --test
  • Add gem requirement to app config.rb with a version and source
  • When you clone or deploy an app, run rake:gems
  • Do not vendor gems
  • Is there is a gem version?
  • Yes: use it because gems are better.
  • No: install the plugin using script/install plugin
  • Can you refactor it to be a gem or plugin?
  • Yes: refactor
  • No: create a git project, upload it to the org's github shared folder.


Rake gems

The app will define its gems in config.rb, then we use rake gems.

Rake plugins

The org's base app will not come with pre-installed plugins.
Instead, it should have a rake task (TBD) that installs plugins,
possibly by prompting the developer yes/no for each plugin.
e.g. "Do you want to use Hoptoad to report your exceptions?"

Rake submodules

We want a rake task that creates git submodules for shared files,
possibly by prompting the developer yes/no for each submodule,
e.g. "Do you want to use Dave's gray CSS layout?"

Naming Convention

Create a "shared" directory for models, views, controllers, etc.
e.g. models/shared/foo/, views/shared/goo/, controllers/shared/hoo


Make your shared code as small and as specific as possible,
because this is easier to test, deploy, document, and update.


We may want/need to create aggregator gems and git models
that bundle some of our small gems with related functionality.

Gem Server

We want a gem server where we can share org-protected gems,
ideally with password protection and also external availability.


When we create fixes to public gems and plugins,
we want to submit the fixes upstream to the authors
rather than managing our our forks/clones/copies,
e.g. we want annotate_models to omit line numbers.

Open Source

We want to create ways for the org to contribute to open source.
A good first candidate is improvements to existing public gems.

What's Next?

blog comments powered by Disqus