Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing Model code between Sinatra and Rails

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?

like image 216
parasquid Avatar asked Apr 29 '12 21:04

parasquid


1 Answers

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

like image 129
Konstantin Haase Avatar answered Nov 15 '22 09:11

Konstantin Haase