【问题标题】:Dangers of putting a gem into a gemfile is someone trying to install it doesn't support the gem?将 gem 放入 gemfile 的危险是有人试图安装它不支持 gem?
【发布时间】:2014-01-02 14:57:23
【问题描述】:

如果我有一些同事的旧版 Mac OS X 不支持我想使用的 gem(特别是 terminal-notifier),那么将其放入 Gemfile 是否有危险:

gem 'terminal-notifier'

有没有办法说它需要 OS X 10.8 或更高版本?如果

【问题讨论】:

    标签: ruby macos rubygems bundler gemfile


    【解决方案1】:

    将以下条件放入

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

    这应该可行。我知道在 10.4 的情况下uname -r8.x,而 10.5 的uname -r9.x

    或致电sw_vers 应用程序:

    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
    

    【讨论】:

    • 如果您无法加载 gem,请提供您 uname -r 的结果。我无法测试代码。
    • 不适用于我(小牛队),因为uname -r 返回"13.0.0"。我认为更好的方法是`sw_vers -productVersion` >= '10.9'
    • 当然,sw_vers -productVersion 会更好,但显示你的RUBY_PLATFORM
    • "x86_64-darwin13.0"
    • @Miles 这取决于宝石。如果需要编译,它可能会在安装过程中崩溃,并且 bundle install 之类的东西将不起作用。如果它是预编译的(如终端通知程序)或纯 Ruby,它可能会成功安装,但无法正常工作或根本无法工作。
    猜你喜欢
    • 2011-12-08
    • 2017-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多