Module: RecentRuby
- Defined in:
- lib/recent_ruby.rb,
lib/recent_ruby/version.rb,
lib/recent_ruby/xml_ast.rb
Defined Under Namespace
Classes: XMLAST
Constant Summary collapse
- VERSION =
'0.1.0'.freeze
Instance Method Summary collapse
- #check_eol(version, version_base_url) ⇒ Object
- #compare_versions(version, latest, minor) ⇒ Object
- #get_rubies(versions_url) ⇒ Object
- #http_get(url) ⇒ Object
- #latest_minor_version(rubies, minor) ⇒ Object
- #parse_gemfile(gemfile) ⇒ Object
- #validate_args(gemfile, version) ⇒ Object
- #validate_mri_version(version) ⇒ Object
Instance Method Details
#check_eol(version, version_base_url) ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/recent_ruby.rb', line 64 def check_eol(version, version_base_url) puts "Downloading details for #{version}..." details = http_get("#{version_base_url}#{version}") puts 'Checking EOL status...' return unless details =~ / warn_eol / puts "EOL warning found for #{version}!" exit 1 end |
#compare_versions(version, latest, minor) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/recent_ruby.rb', line 74 def compare_versions(version, latest, minor) puts 'Comparing version numbers...' return if version == latest puts "Current version is #{version}, but the latest patch release for #{minor.join('.')} is #{latest}!" exit 1 end |
#get_rubies(versions_url) ⇒ Object
47 48 49 50 |
# File 'lib/recent_ruby.rb', line 47 def get_rubies(versions_url) puts 'Downloading latest list of Rubies from Github...' JSON.parse(http_get(versions_url)) end |
#http_get(url) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/recent_ruby.rb', line 5 def http_get(url) uri = URI(url) Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http| request = Net::HTTP::Get.new uri response = http.request request if response.code != '200' puts "Error: received HTTP #{response.code} response from Github:\n\n#{response.body}" exit(2) end response.body end end |
#latest_minor_version(rubies, minor) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/recent_ruby.rb', line 52 def latest_minor_version(rubies, minor) minor_rubies = rubies.map { |n| n['name'] }.select do |n| n =~ /^\d+\.\d+\.\d+(-p\d+)?$/ && n.split('.')[0, 2] == minor end minor_rubies.max_by do |ruby| a, b, c, d = *ruby.sub('-p', '.').split('.').map(&:to_i) [a, b, c, d || -1] end end |
#parse_gemfile(gemfile) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/recent_ruby.rb', line 29 def parse_gemfile(gemfile) ast = Parser::CurrentRuby.parse(File.read(gemfile)) xml = RecentRuby::XMLAST.new(ast) version = xml.xpath("//send[symbol-val[@value='ruby']]/str/string-val/@value") || [nil] version = version.first ? version.first.value : nil unless version puts 'Unable to find ruby version in gemfile.' exit(1) end version end |
#validate_args(gemfile, version) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/recent_ruby.rb', line 19 def validate_args(gemfile, version) if gemfile && version puts 'Please supply only one argument. Run with -h for more information.' exit(1) elsif !gemfile && !version puts 'Please supply either a gemfile path or a version string. Run with -h for more information.' exit(1) end end |
#validate_mri_version(version) ⇒ Object
41 42 43 44 45 |
# File 'lib/recent_ruby.rb', line 41 def validate_mri_version(version) return if version =~ /^(\d+\.\d+\.\d+(-p\d+)?)$/ puts 'Only stable release MRI version strings are currently supported. (e.g. 2.3.1 or 2.3.1-p12)' exit(1) end |