Is it a Bad Practice to Have Both a .rvmrc and a .ruby-version in a Ruby Project?
Asked Answered
C

1

1

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)

Conveyance answered 20/1, 2016 at 16:38 Comment(6)
I my opinion it is a good practice to define the Ruby version against which the project is build and tested. Because when developers try to run the same project with different Ruby versions they will run into problems sooner or later. Since the .ruby-version (and the Gemfile if you run your app in Heroku) is the de facto standard, I see no benefit in maintaining older, incompatible file types.Escaut
I'd do what the rvm warning says, and delete the .rvmrc and just use .ruby-version. That's what the warning is telling you, right?Goosefish
@Goosefish sort-of. The caveat there is it actually generates a new file, named something like .ruby-version-DD-MM-YY-SOMEOTHERMETADATA (I forget the exact pattern), and in addition to that, it sets the wrong patch number in the new .ruby-version... file. I could edit this manually and leave it, but then Im circumventing the auto-magic behavior of the rvm command, and that feels hacky. Plus Im making changes to files not requested by my client, and Im not sure what effect it will have on the other contractors envs.Conveyance
Okay, you already have a .ruby-version, you don't need it to generate it for you, that's just a convenience which is not turning out convenient for you. Why would you need rvm to generate a .ruby-version file for you if you already have one? I'd manually make sure it's set to the correct ruby version, probably the same one that was in the .rvmrc.Goosefish
Ah sorry I diddnt read your comment thoroughly, I thought you were suggesting running the rvm rvmrc to ruby-version command, which produces what I described above. I also am in agreement with you, and this is what I plan to do, Im really just making sure this isnt due to some kind of established convention Im unaware of, as Ive only been developing in Ruby 2 to 3 years.Conveyance
I wouldn't version either. Use bundler for this: bundler.io/v1.3/gemfile_ruby.htmlWalter
C
3

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.

Conveyance answered 16/2, 2016 at 13:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.