Skip to content

Instantly share code, notes, and snippets.

@suu-g
Last active December 29, 2015 01:39
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save suu-g/7595264 to your computer and use it in GitHub Desktop.
Save suu-g/7595264 to your computer and use it in GitHub Desktop.
Check if your environment can use the latest libv8 without compiling it
require 'rubygems'
require 'rubygems/dependency_installer'
require 'json'
require 'open-uri'
class GemVersions
def initialize(gem)
@gem = gem
@versions = JSON.parse(
open("http://rubygems.org/api/v1/versions/#{gem}.json").read
)
end
def native(plat=Platform.new)
@versions.select{|x|
x["platform"] == plat.platform.to_s
}.map{|x|
x["number"]
}.first
end
def latest
@versions.first["number"]
end
end
class Platform
def initialize(platform=nil)
@platform = platform ?
Gem::Platform.new(platform) :
Gem::Platform.new(RUBY_PLATFORM)
end
def platform=(platform)
new_plat = Gem::Platform.new(platform)
@platform = new_plat
return platform
rescue => e
nil
end
def platform
@platform.to_s
end
end
if $0 == __FILE__
gem = "libv8"
version = GemVersions.new(gem)
if version.native
puts "gem '#{gem}', '#{version.native}'"
else
puts "gem '#{gem}', '~> #{version.latest}'"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment