将gem放入gemfile的危险是有人试图安装它不支持gem?

问题描述 投票:0回答:1

如果我的某些同事有一个旧版本的Mac OS X不支持我想要使用的宝石(特别是terminal-notifier),是否存在把它放入Gemfile的危险:

gem 'terminal-notifier'

有没有办法说它需要OS X 10.8或更高版本?如果<10.8的某个人试图安装终端通知器会怎样?我正在使用最新的操作系统,因此无法对此进行测试。

ruby macos rubygems bundler gemfile
1个回答
2
投票

放入以下条件:

if RUBY_PLATFORM =~ /darwin/i
   version = `uname -r` =~ /^(\d+)\./ && $1.to_i
   gem 'terminal-notifier' if version >= 12
end

这应该工作。我知道,在 10.4的情况下,uname -r是8.x,而是10.5,uname -r是9.x.

或者致电sw_vers app:

if RUBY_PLATFORM =~ /darwin/i
   version = `sw_vers -productVersion` =~ /^10\.(\d+)/ && $1.to_i
   gem 'terminal-notifier' if version >= 9
end

如果要计划一起运行,你必须使用rbconfig模块。

if RbConfig::CONFIG['host_os'] =~ /darwin|mac os/i
   version = `sw_vers -productVersion` =~ /^10\.(\d+)/ && $1.to_i
   gem 'terminal-notifier' if version >= 9
end
© www.soinside.com 2019 - 2024. All rights reserved.