0

If I have some coworkers that have an old version of Mac OS X that doesn't support the gem I want to use (terminal-notifier specifically), are there dangers of putting this into the Gemfile:

gem 'terminal-notifier'

Is there some way to say that it requires OS X 10.8 or greater? What happens if someone on < 10.8 tries to install terminal-notifier? I'm on the latest os so I can't exactly test this.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Miles
  • 1,615
  • 4
  • 17
  • 42

1 Answers1

2

Put into the following condition:

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

This should work. I know that in case of 10.4 the uname -r was 8.x, and of 10.5 the uname -r was 9.x.

Or with call to sw_vers app:

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

In case when the is to be planned to run with you have to use rbconfig module.

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
Малъ Скрылевъ
  • 16,187
  • 5
  • 56
  • 69
  • If you could't load the gem, please provide me result of your `uname -r`. I can't test the code. – Малъ Скрылевъ Jan 02 '14 at 15:17
  • 1
    Does not work for me (Mavericks) as `uname -r` returns `"13.0.0"`. I think that better approach is `\`sw_vers -productVersion\` >= '10.9'` – mechanicalfish Jan 02 '14 at 15:19
  • of course, `sw_vers -productVersion` would be better, but show your `RUBY_PLATFORM` – Малъ Скрылевъ Jan 02 '14 at 15:22
  • `"x86_64-darwin13.0"` – mechanicalfish Jan 02 '14 at 15:24
  • @majioa and mechanicalfish thanks! I'd still like to know what happens if you try to install a gem that your os doesn't support. Either of you know? – Miles Jan 02 '14 at 15:32
  • @Miles close the gem under the `if RUBY_PLATFORM` condition. – Малъ Скрылевъ Jan 02 '14 at 15:35
  • Beware of JRuby, it will always display `java` as `RUBY_PLATFORM`. I believe you can use `require 'rbconfig'; RbConfig::CONFIG['host_os']` instead. – Patrick Oscity Jan 02 '14 at 15:38
  • 1
    @Miles it depends on the gem. If it needs to be compiled, it may crash during installation and things like bundle install won't work. If it's precompiled (like terminal-notifier) or pure Ruby it will probably install successfully but won't work properly or at all. – mechanicalfish Jan 02 '14 at 15:44
  • @majioa I ended up not using this because while I'm developing on a Mac, I'm deploying to an unix box. When I use cap to deploy it notices its gemfile.lock is different than the one in the repo, so rolls back the deploy. – Miles Jan 02 '14 at 16:38