Last active
December 29, 2015 01:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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