Skip to content

Instantly share code, notes, and snippets.

@wingrunr21
Created October 11, 2013 22:52
Show Gist options
  • Save wingrunr21/6943236 to your computer and use it in GitHub Desktop.
Save wingrunr21/6943236 to your computer and use it in GitHub Desktop.
A simple utility module we used to detect the version of OS X currently running in order to work around the oracle-instant-client segfault problem.
module OSXCompat
OSX_REGEX = /darwin\d{2}/
SNOW_KITTY = "darwin10"
class << self
def snow_kitty_or_lower?
if darwin?
osx_version <= SNOW_KITTY
else
true #always return true for every other env
end
end
def use_oracle?
eval_environment_value_or_fallback 'USE_ORACLE', :snow_kitty_or_lower?
end
def use_image_tools?
eval_environment_value_or_fallback 'USE_IMAGE_TOOLS', :lion_or_higher?
end
def lion_or_higher?
!snow_kitty_or_lower?
end
def darwin?
!osx_version.nil?
end
def osx_version
RUBY_PLATFORM.slice OSX_REGEX
end
protected
def eval_environment_value_or_fallback(value, fallback)
v = ENV[value]
v && v =~ /\Atrue|false\Z/ ? eval(v) : send(fallback)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment