为 Rails 项目分叉 gem

发布于 2024-08-08 06:29:21 字数 280 浏览 2 评论 0原文

我发现自己遇到过两次这种情况:我在我的系统上安装了一个 gem,并开始从我的 Rails 项目中使用它。最终我需要对该宝石进行一些更改。我应该如何进行?

理想情况下,我想在某个地方查看该 gem 的源代码,例如 ~/third_party/gems,对其进行处理并让我的 Rails 项目使用它。这可能吗?

在所有情况下,gem 都在 github 上,所以我可能会在 github 上获取它,克隆它,抓住机会并维护我自己的分支。我想然后我会直接使用 gem install 在我的服务器上安装该分支。这有道理吗?

I've found myself twice in this situation: I install a gem on my system and start using it from my Rails project. Eventually I need to make some changes to that gem. How should I proceed?

Ideally I'd like to check out the source code of that gem somewhere, like ~/third_party/gems, work on it and have my Rails project use that instead. Is that possible?

In all the cases the gems were at github so I would probably for it at github, clone it, make my chances and maintain my own branch. I suppose then I would install that branch directly with gem install on my server. Does that make sense?

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

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

发布评论

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

评论(2

感受沵的脚步 2024-08-15 06:29:21

如今,使用 Bundler 可以很轻松地做到这一点。您制作 gem 的本地副本,然后不再

gem "whatever"

在 Gemfile 中执行操作,而是执行以下操作:

gem "whatever", :path => "/home/pupeno/whatever"

运行捆绑安装后,将从该目录中选取 gem。即使您修改了其中的某些内容,您只需重新启动 Rails 即可重新加载它。

如果您需要使用自己对 Gem 的更改来部署应用程序,您可以在 Github 或类似的地方以及您所做的 Gemfile 上创建一个分支:

gem "whatever", :git => "[email protected]:/pupeno/whatever.git"

就是这样。它简单、直接、美观。

Today this is pretty easy to do with Bundler. You make a local copy of the gem and then instead of doing

gem "whatever"

in your Gemfile, you do:

gem "whatever", :path => "/home/pupeno/whatever"

After running bundle install, the gem is picked from that directory. Even if you modify something in there, all you need to do to re-load it is restart Rails.

If you need to deploy an application using your own changes of a Gem, you make a fork, on Github or similar and on the Gemfile you do:

gem "whatever", :git => "[email protected]:/pupeno/whatever.git"

and that's it. It's simple, straightforward and beautiful.

你曾走过我的故事 2024-08-15 06:29:21

在所有情况下,gem 都在 github 上,所以我可能会在 github 上获取它,克隆它,抓住机会并维护我自己的分支。我想然后我会直接使用 gem install 在我的服务器上安装该分支。

如果您确实需要破解实际的宝石源,那么是的,这就是实现它的方法。然而,这应该是最后的手段。如果没有必要,您不想维护实际的 gem。为什么不从 gem 源扩展类(您需要更改其功能)并使用您的类而不是 Rails 代码中的 gem 类?

我发现您实际上很少需要直接破解第 3 方代码来完成您需要做的事情。好的软件可以扩展/轻松增强。

In all the cases the gems were at github so I would probably for it at github, clone it, make my chances and maintain my own branch. I suppose then I would install that branch directly with gem install on my server.

If you really need to hack the actual gem source then yes, that would be the way to do it. However, it should be a last resort. You don't want to maintain the actual gem if you don't have to. Why not extend classes from the gem source whose functionality you need to change and use your classes instead of the gem classes in your Rails code?

I find it rare that you actually need to hack 3rd party code directly to do what you need to do. Good software can be extended/easily augmented.

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