[英]Specify different Ruby versions (e.g. 1.9.3 vs 2.1) in Gemfile for Windows and Linux/OS X?
I'm on a Ruby on Rails project where we have Windows and Linux computers. 我在Ruby on Rails项目中,我们有Windows和Linux计算机。 The project uses Ruby 2.1, but as a windows dev I need to use a lower version of Ruby like ruby 1.9.3 or Ruby 2.0 in order to smoothly do local dev work.
该项目使用Ruby 2.1,但作为Windows开发人员,我需要使用较低版本的Ruby(如ruby 1.9.3或Ruby 2.0)才能顺利进行本地开发工作。
So to implement custom Ruby versions for my Rails project based on platform automatically, I tried to modify the Gemfile to segregate different Gems and Ruby Versions for each platform: 因此,为了自动基于平台为我的Rails项目实现自定义Ruby版本,我尝试修改Gemfile以为每个平台隔离不同的Gems和Ruby版本:
platforms :ruby do # linux & Mac only
ruby '2.1.0' #doesn't work, still tries to load ruby 1.9.3
gem 'puma', '~> 2.7.1' #works
end
platforms :mswin do #Windows only
ruby '1.9.3' #doesn't work, overrides Linux/mac users to Ruby 1.9.3 rather than 2.1
gem 'thin' # works
end
platforms :ruby
or platforms :mswin
apparently only works for designating Gems, and doesn't work for specifying Ruby versions. platforms :ruby
或platforms :mswin
显然仅适用于指定Gems,而不适用于指定Ruby版本。 How do I set up my local windows dev environment so that I can work on a lower/different Ruby version automatically within the same Gemfile without affecting my co-workers? 如何设置本地Windows开发环境,以便可以在同一Gemfile中自动处理较低/不同的Ruby版本,而又不影响我的同事?
.rubyversion
reads 2.1.0
While I could .gitignore
this file to specify for each environment, Heroku requires us to specify a Ruby version within the Gemfile--so we need some way to resolve this at the Gemfile level. .rubyversion
读取2.1.0
虽然我可以.gitignore
来为每个环境指定该文件,但是Heroku要求我们在Gemfile中指定一个Ruby版本-因此我们需要某种方法在Gemfile级别上对此进行解析。
Gemfile是用Ruby实现的DSL,因此您可以在这里调用Ruby代码:
ruby RUBY_PLATFROM =~ /win/ ? '1.9.2' : '2.1.0'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.