Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails code sharing: gem vs plugin vs submodule?

Here's the scenario: small closed-source project that needs to share a certain model across multiple Rails apps. Basically there's one DB and multiple apps reading/writing to it in different ways, but all through that same interface. I would like to have the code for this DAL be implemented in only one place and shared somehow with all of the projects that need it.

What is the optimal way of doing that with the latest Rails version, assuming I'm using git as VCS? The three contenders you always read about are gems (which I understand can be created for internal use only, given you host your own gem server), Rails plugins and git submodules.

I haven't been able to find an overview of why, given all three options, one might want to pick one over another. I was hoping you folks might help me out!

Thank you!

like image 863
Alexandr Kurilin Avatar asked Apr 21 '26 10:04

Alexandr Kurilin


2 Answers

I suggest you use gems, and bundle them in your application. We are using several private gems and keep them in the vendor/cache directory.

Plugins are deprecated, and will be removed. (Rails 4.0 I believe will remove them) They also cause warning spew.

Using a submodule is an interesting idea, but I would still stick with a gem.

like image 199
x1a4 Avatar answered Apr 22 '26 22:04

x1a4


Encapsulating some common code into a gem is a good practice nowdays. There's a Gemfury, proclaiming itself as a "private gem cloud server", which provides a service of storing private gems.

like image 21
gmile Avatar answered Apr 22 '26 23:04

gmile



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!