简体   繁体   English

Gemfile中的条件

[英]conditionals in Gemfile

Our team uses different databases for each other, and we are using bundler so our Gemfile contains the repo creator's db connector(mysql) 我们的团队互相使用不同的数据库,我们正在使用bundler,因此我们的Gemfile包含repo creator的db连接器(mysql)

I am using pg and due to a bit laziness and fear of breaking something, I don't want to use mysql, so I just add a gem "pg" in our Gemfile. 我正在使用pg,由于有点懒惰和害怕破坏,我不想使用mysql,所以我只是在我们的Gemfile中添加一个gem“pg”。

Of course, since we're using git, it will always show as a modified file, and we all use the Gemfile so we can't gitignore it or commit it with our changes. 当然,既然我们正在使用git,它将始终显示为已修改的文件,并且我们都使用Gemfile,因此我们无法对其进行gitignore或将其与我们的更改一起提交。

Question is, how do we go about this? 问题是,我们该如何解决这个问题? Is there a conditional in bundler or do I just have to declare that I'm using a certain gem someplace else? 在捆绑器中是否存在条件或我是否必须声明我在其他地方使用某个宝石?

Since Gemfile , like Rakefile , is just a chunk of Ruby, you can throw in conditionals if you think it will simplify your life. 由于GemfileRakefile一样,只是Ruby的一大块,如果你认为它可以简化你的生活,你可以抛出条件。 For instance: 例如:

if (Gem.available?('pg'))
  gem 'pg'
else
  gem 'mysql2'
end

Sometimes you have to do this for different Ruby versions as 1.8 and 1.9 sometimes need different gems. 有时您必须为不同的Ruby版本执行此操作,因为1.8和1.9有时需要不同的宝石。

You can use a group. 你可以使用一个组。 Yehuda Katz explain it how here (taking in example the pg gem) http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/ Yehuda Katz在这里解释它(以示例pg gem为例) http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

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

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