在Ruby项目中拥有.rvmrc和.ruby版本是不是一个坏习惯? [英] Is it a Bad Practice to Have Both a .rvmrc and a .ruby-version in a Ruby Project?

查看:258
本文介绍了在Ruby项目中拥有.rvmrc和.ruby版本是不是一个坏习惯?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在开发两个Ruby项目,它们都有一个 .rvmrc 和一个 .ruby-version 文件在他们的根目录。我使用 rvm 来管理我的本地开发环境中的Ruby版本,并在我的主目录的各种Ruby副本中拥有我自己的本地 .rvmrc 版本,当我将目录更改为这些项目时,我自然会得到 rvm 警告:


.rvmrc',它需要信任,它比较慢,它与其他ruby管理器不兼容,
你可以使用'rvm rvmrc到ruby-version'
切换到'.ruby-version'或忽略这个使用'rvm rvmrc warning ignore /home/ME/craft/ruby/rails/CLIENT/APPLICATION/.rvmrc'的警告,
'.rvmrc'将继续作为RVM 1和RVM 2中的默认项目文件,
忽略运行'rvm rvmrc warning ignore all.rvmrcs'的所有文件的警告。


我觉得这是奇怪的首先在同一个项目中同时拥有两个配置的dotfiles,并且认为它可能是Ruby文化的历史怪癖,我不知道(真的是一个不太认真的语言通才)。就个人而言,我从来没有在项目中使用 .rvmrc ,而且我一年在10-15个Ruby项目中工作,很少看到这个文件。 >

这两个项目的第二个问题真的出现在这些项目中,其中 .rvmrc 文件具有较旧的Ruby版本比 .ruby-version 。这导致了我解决的我当地环境的一些并发症,虽然我觉得有点尴尬。更糟糕的是,我修改了我的环境( git )'master'分支的项目,当我切换到最新的功能分支, .ruby版本文件已更新为另一个不同的修补程序编号。所以我重复了重新安装 ,重新安装所有的gems,我选择手动切换到这个补丁版本。我不确定上述的正确方式,这种方式似乎适用于我的环境(以复制宝石和占用我硬盘上的一点空间为代价)。



我担心为什么一个项目将会同时定义这两个文件,特别是关注每个文件中具有不同版本/修补程序号的项目。



这是正常吗?通过从项目中删除 .rvmrc 文件来解决这个问题吗?至少应该将 .rvmrc 文件更新为与 .ruby-version 文件?我本能地觉得这是对的,但是想要知道关于 rvm 和维护Ruby版本的其他方法的任何一种历史,这些实际上可能使得这个决定变得合理。任何人都可以传达这种情况可能会如何发展的历史,还是只是随着时间的推移,厨房中的厨师太多了?



涉及 .ruby-version 和Gemfile)

是一个不好的做法,因为它一次维护两个公约,这可能导致某些环境中的版本管理问题。这也使得其中一个公约与项目中使用的ruby版本不符合另一个约定。此时$ .ruby-version 文件更为常规,因此最好删除 .rvmrc 文件并且只保留 .ruby-version


There are two Ruby projects I am currently working on which have both a .rvmrc and a .ruby-version file in their root dir. I use rvm to manage my Ruby versions in my local development environment, and have my own local .rvmrc files in my home directory's copy of various Ruby versions, so naturally I get the rvm warning when I change directory into these projects:

You are using '.rvmrc', it requires trusting, it is slower and it is not compatible with other ruby managers, you can switch to '.ruby-version' using 'rvm rvmrc to ruby-version' or ignore this warning with 'rvm rvmrc warning ignore /home/ME/craft/ruby/rails/CLIENT/APPLICATION/.rvmrc', '.rvmrc' will continue to be the default project file in RVM 1 and RVM 2, to ignore the warning for all files run 'rvm rvmrc warning ignore all.rvmrcs'.

I felt it was odd to have both configuration dotfiles in the same project at first, and figured that it might be a historical quirk to the Ruby culture that I was unaware of (Im a less-opinionated language generalist, really). Personally I never use .rvmrc in a project, and I work on 10-15 Ruby projects in a year, and rarely see this file in anything I work with.

The problem really arises on the 2nd of these two projects, where the .rvmrc file has an older patch of the Ruby version than the .ruby-version. This resulted in some complications for my local environment that I resolved, though I feel its a bit awkward. To make it worse, I fixed my environment for the (git) 'master' branch of the project, and when I switched to the latest feature branch, the .ruby-version file was updated to yet another different patch number. So I repeated things like reinstalling bundler, reinstalling all the gems, and I choose to manually switch to this patch version. I am unsure of the 'correct' way to do the above, and this way seems to work for my environment (at the cost of duplicating gems and taking up a bit of space on my hard disk).

I am concerned as to why a project would have both these files defined, and especially concerned for a project that has differing versions/patch numbers in each file.

Is this normal? Should this be rectified by removing the .rvmrc file from the project? Should the .rvmrc file, at the very least, be updated to the same version and patch number as the .ruby-version file? I instinctively feel this isnt right, but want to be aware of any sort of history regarding rvm and other methods for maintaining Ruby versions which might actually make this decision sensible. Can anyone relay the history of how such a situation might sensibly evolve, or is it just a symptom of too many cooks in the kitchen over time?

(possibly related question concerning .ruby-version and Gemfile)

解决方案

It is a "bad practice" in that it maintains two conventions at once, which can lead to version management issues in some environments. It also makes it possible for one of the conventions to fall out of sync with the other in regards to the version of ruby used in the project. The .ruby-version file is more conventional at this time, so it would be best to remove the .rvmrc file and only maintain .ruby-version.

这篇关于在Ruby项目中拥有.rvmrc和.ruby版本是不是一个坏习惯?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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