为 Rails 项目分叉 gem [英] Forking a gem for a Rails project

查看:20
本文介绍了为 Rails 项目分叉 gem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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?

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

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?

在所有情况下,gem 都在 github,所以我可能会在 github 上找到它,克隆它,创造机会并维护我自己的分支.我想我会直接在我的服务器上使用 gem install 安装该分支.这有意义吗?

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?

推荐答案

今天,使用 Bundler 很容易做到这一点.您制作 gem 的本地副本,然后而不是这样做

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

gem "whatever"

在您的 Gemfile 中,您可以:

in your Gemfile, you do:

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

运行 bundle install 后,gem 将从该目录中选取.即使您在其中修改了某些内容,也只需重新启动 Rails 即可重新加载它.

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.

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

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 => "git@github.com:/pupeno/whatever.git"

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

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

这篇关于为 Rails 项目分叉 gem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆