class SpecDiff
A class to encapsulate the difference between gem states
Public Class Methods
Configure the diff
# File support.rb, line 44 def initialize(*args) super # Check for prerelease - Gem rules are that a letter indicates a prerelease # See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html#method-i-prerelease-3F @prerelease = version_in_use =~ /[a-zA-Z]/ end
Public Instance Methods
Return a :month1, :month6, :year1, :more depending on the build age of the available version
# File support.rb, line 53 def build_age build_date = version_build_date(version_in_use) return :none if build_date.nil? days = ((Time.now.utc - build_date)/(24 * 60 * 60)).round case when days < 31 then :month1 when days < 182 then :month6 when days < 366 then :year1 else :more end end
Classify this as :current, :update or :obsolete
# File support.rb, line 66 def classify case when (version_available == version_in_use) then :current when (dep.match?(name, version_available)) then :update else :obsolete end end
# File support.rb, line 76 def name; dep.name; end
# File support.rb, line 74 def prerelease?; @prerelease; end
Is there a suggested version - e.g. if you’re using rails 3.0.8, the most current might be 3.1.0. However, the suggested version would be 3.0.10 – this will suggest the best version within your current minor version tree. May return nil if you’re at the current suggestion, or if there is no reasonable match
# File support.rb, line 83 def suggest match = nil head = version_in_use.rpartition('.').first versions.sort_by { |v| v['built_at'] }.reverse.each do |ver| ver = ver['number'] match = ver and break if ver.start_with?(head) end (match == version_in_use) || (match == version_available) ? nil : match end
String representation is the basic spec form ‘gename (version)’, with a start appended for prereleases.
# File support.rb, line 95 def to_s "#{spec}#{prerelease? ? '*' : ''}" end
Best version available according to RubyGems data
# File support.rb, line 115 def version_available return gemdata["version"].to_s unless prerelease? # Depends if it's a prerelease or not prereleases = versions.select { |v| v['prerelease']}.map { |v| v['number'] } prereleases.first # Big Assumption, but appears correct on data so far end
Return the build date for a given version string (e.g. ‘1.2.1’)
# File support.rb, line 106 def version_build_date(version) return nil if versions.nil? || versions.empty? data = version_data(version) return nil if data.nil? version_date = data['built_at'] version_date.nil? ? nil : Time.parse(version_date) end
Return the version data for a given string
# File support.rb, line 100 def version_data(version) return nil if versions.nil? || versions.empty? version = versions.find { |v| v['number'] == version } end
The version currently in use according to the lockfile
# File support.rb, line 124 def version_in_use; spec.version.to_s; end