为Rails项目分配一个gem [英] Forking a gem for a Rails project

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

问题描述

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



理想情况下,我想查看某个地方的gem源代码,比如〜/ third_party / gems,使用它并让我的Rails项目使用,而不是。这是可能的吗?



在所有情况下,gem都在github上,所以我可能会在github上克隆它,让我的机会和维护自己的分支。我想那时我会直接用我的服务器上的gem install来安装那个分支。这是否有意义?

解决方案

今天这对Bundler来说很容易。您创建一个gem的本地副本,然后而不是做

  gemwhatever
 gemwhatever,:path => / home / pupeno / whatever

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



如果您需要使用自己的宝石,你在Github上或类似的Gemfile上做了一个分支:

  gemwhatever,::git = > git@github.com:/pupeno/whatever.git

就是这样。这很简单,直接,美丽。


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?

解决方案

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

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

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

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