简体   繁体   English

在多个Rails应用程序中重用Ruby代码

[英]Reusing Ruby code across several Rails applications

I have developed a simple library in Ruby and need to use this in several Rails applications (some of which are not built yet). 我在Ruby中开发了一个简单的库,需要在几个Rails应用程序中使用它(其中一些还没有构建)。 What is the best way to easily add this Ruby library to several Rails applications as and when required? 在需要时,将这个Ruby库轻松添加到多个Rails应用程序的最佳方法是什么? Our team is running Ubuntu and our repository is Mercurial. 我们的团队正在运行Ubuntu,我们的存储库是Mercurial。

Should I use a... 我应该用...

  1. Rails plugin? Rails插件? This would be my first choice but it appears not to support Mercurial?? 这将是我的第一选择,但似乎不支持Mercurial?
  2. Ruby Gem? 红宝石宝石?
  3. Custom Rake script? 自定义Rake脚本?
  4. Other options?? 其他选择??

Any pointers would be much appreciated! 任何指针将非常感谢!

Ruby already has an established mechanism for code sharing ie RubyGems. Ruby已经建立了代码共享机制,即RubyGems。 Jeweler makes Gem creation easy. 珠宝商让宝石创作变得轻松。 I'd recommend that you check it out. 我建议你看看。

Make a gem or a plugin. 制作宝石或插件。 Gems are better in my opinion, easier to manage. 在我看来,宝石更好,更容易管理。

My rule of thumb: 我的经验法则:

If it doesn't depend on rails, make it a gem. 如果它不依赖于铁轨,那就把它变成宝石吧。
If it depends on rails, make it a plugin. 如果它依赖于rails,请将其设为插件。

Make a Rails plugin. 制作一个Rails插件。 It doesn't "support" Mercurial in the sense that you can't do script/plugin install $REPO_URL and have it work automatically, but if it's for your own use, then you won't miss that feature. 它不能“支持”Mercurial,因为你不能做script/plugin install $REPO_URL并让它自动运行,但如果它是你自己使用的,那么你就不会错过这个功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM