Skip to content

Instantly share code, notes, and snippets.

@mkocher
Created September 6, 2012 06:12
Show Gist options
  • Save mkocher/3651970 to your computer and use it in GitHub Desktop.
Save mkocher/3651970 to your computer and use it in GitHub Desktop.
Using a gem for shared project code
Sharing common code using a gem is a great idea, but it's painful to rapidly iterate in both codebases.
What we settled on something like:
if ENV['LOCAL_GEMS']
gem 'shared_stuff', :path => '~/workspace/shared_stuff'
else
gem 'shared_stuff, :github => 'mkocher/shared_stuff'
end
We'd check this in to the project, then we could set the environment variable and rebundle. You'd have
to do this when you decided that you wanted to change the shared code, and then once you're done you push
the changes to the gem, then unset the env variable, then bundle to get the new hash in your gemfile lock.
Invariably someone will forget and check in the lock file pointing to the local copy. CI should catch this
as long as the local path doesn't exist on CI.
Another issue we'd run into was someone would make breaking changes, but not bump everything that uses the
gem. Someone would modify project A, bump shared to match, and leave project B a ticking time bomb.
Someone would come along later to work on B, decided they needed to modify shared, then bump it up and find
things were horribly broken. You want to be locked to a hash for deployment, but you could help this by
having a second CI build that always pointed at HEAD of shared.
We hashed this out on a project about a year and a half ago. You won't get to experience the pain of waiting
2 minutes for bundler to resolve dependencies every time you bundle. (Thanks Bundler team!)
This was certainly better than copying the models, but I'd love to hear if someone has a better workflow.
@TrevorBramble
Copy link

Seems like a lot of fragility and pain for the one benefit.

At this point I'm considering an internal API between the main stack and the API service, with strategic caching on the API side...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment