8

I have a Sinatra application that responds to api calls, and a Rails application that handles the reports and all the pretty stuff like graphs and the website. Both need to have access to a common set of models (e.g. Accounts, Sites, etc.)

My problem is: how do I efficiently share the code between the two applications? For example, if I'm editing the Accounts model in Sinatra, I don't want to have to remember to duplicate the same changes in the Rails app. I'd rather not use Rails Rack mounting as the two applications will be on separate clusters.

I've seen suggestions on StackOverflow about:

  • Git Modules
  • Symlinks (won't work with Windows which my colleague uses)
  • Rails plugins (I doubt this would work with Sinatra)
  • Ruby Gems (I think this is too overkill for just model data, but that's just me)

The two apps are in different repositories. Basically, I'm first developing the API, then putting on the Account specific logic later in the Rails app (mainly because Rails has a lot more libraries that make it easier to develop these sort of things).

How would you solve this problem?

parasquid
  • 157
  • 8

1 Answers1

4

I'd go for a gem, or rather something gem like, you don't need to publish it, and then use Bundler git dependencies. We do this heavily at Travis CI and it works great, especially with the new "local" git dependencies in Bundler 1.2: http://gembundler.com/man/bundle-config.1.html#LOCAL-GIT-REPOS

Konstantin Haase
  • 25,687
  • 2
  • 57
  • 59
  • Just to clarify, that means I'll have to extract the commonalities between the two applications into the gem, right? If that's the case, would you happen to know of a repository I can inspect and learn from that uses this technique? :) – parasquid Nov 07 '12 at 17:54
  • Yes, that's what I meant. An alternative would be to either have the Sinatra app an the Rails app in the same project, or have the Sinatra app load the Rails app. Check out https://github.com/travis-ci/travis-core for an example. – Konstantin Haase Nov 17 '12 at 10:23