如何抽象出多个 Rails 应用程序的核心功能?

发布于 2024-08-28 18:31:43 字数 587 浏览 5 评论 0原文

我想开发一些重要的 Rails 应用程序,它们都实现一组核心功能,但每个应用程序都有某些特定的自定义、扩展和审美差异。如何提取所有这些系统共有的核心功能(模型、控制器、帮助器、支持类、测试),以便更新核心将使基于它的每个应用程序受益?

我见过 Rails Engines,但它们似乎太独立,几乎太抽象而无法构建。我认为它们对于向现有应用程序添加一个组件很有用,例如将博客引擎连接到现有的电子商务网站。由于引擎似乎大多是独立的,因此在保持 DRY 的同时覆盖它们的功能和视图似乎很困难且不方便。

我也考虑过将代码抽象成 gem,但这似乎有点奇怪。我是否使 gem 依赖于 Rails gem,以及定义模型和模型?里面的控制器,然后在我的各种应用程序中对它们进行子类化?或者我是否在 gem 中定义了许多模块,并将其包含在各种应用程序的不同位置?如何测试 gem,然后测试其上的自定义设置和覆盖功能集?我还关心如何协同开发 gem 和 Rails 应用程序,我可以将 gem 的 git 存储库供应到应用程序中并从中推送,这样我就不必每次迭代都构建新的 gem 吗?另外,是否有私人宝石托管/我可以设置自己的宝石源吗?

另外,对于此类事业有什么一般性建议吗?要遵守的抽象范式?必读?以前做过这件事的智者的评论?谢谢!

I'd like to develop a number of non-trivial Rails applications which all implement a core set of functionality but each have certain particular customizations, extensions, and aesthetic differences. How can I pull the core functionality (models, controllers, helpers, support classes, tests) common to all these systems out in such a way that updating the core will benefit every application based upon it?

I've seen Rails Engines but they seem to be too detached, almost too abstracted to be built upon. I can seem them being useful for adding one component to an existing app, for example bolting on a blog engine to your existing e-commerce site. Since engines seem to be mostly self contained, it seems difficult and inconvenient to override their functionality and views while keeping DRY.

I've also considered abstracting the code into a gem, but this seems a little odd. Do I make the gem depend on the Rails gems, and the define models & controllers inside it, and then subclass them in my various applications? Or do I define many modules inside the gem that I include in the different spots inside my various applications? How do I test the gem and then test the set of customizations and overridden functionality on top of it? I'm also concerned with how I'll develop the gem and the Rails apps in tandem, can I vendor a git repository of the gem into the app and push from that so I don't have to build a new gem every iteration? Also, are there private gem hosts/can I set my own gem source up?

Also, any general suggestions for this kind of undertaking? Abstraction paradigms to adhere to? Required reading? Comments from the wise who have done this before? Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文