require 'dionysus' require 'active_support/core_ext/kernel/reporting' require 'active_support/core_ext/module/delegation' module Dionysus ## # = VersonString # # require 'dionysus/version_string' # # VersionString is a proxy to Gem::Version that modifies the comparable # interface on String to compare based on the Gem::Version comparator. # It also adds a +satisfies?+ method to check for a Gem::Requirement. # # In addition, requiring VersionString changes the +RUBY_VERSION+ constant # into a VersionString. Because VersionString "is a" String, there should be # no ill-effects with this change since only the Comparable interface is # overriden and this does not change the original operation of the == method. # # The comparator works by converting strings into Gem::Version objects, so # this still works as you would expect: # # RUBY_VERSION < '1.9' class VersionString < String include Comparable ## # Initializes a VersionString and freezes itself. def initialize(*args) super(*args) to_rubygem_version freeze end ## # Compares this VersionString to another String, VersionString, or # Gem::Version. # # Examples: # # Dionysus::VersionString.new('1.0') > '1.0' => false # Dionysus::VersionString.new('1.0') == Gem::Version('1.0') => true # Dionysus::VersionString.new('1.0') <=> Dionysus::VersionString.new('1.0') => 0 # # See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html def <=>( obj ) obj = obj.dup if obj.is_a?(String) or obj.is_a?(Gem::Version) obj = Gem::Version.create(obj) else raise ArgumentError, "Can only compare to a Dionysus::VersionString/String or Gem::Version" end self.to_rubygem_version <=> obj end alias_method :"eql?", :"==" ## # Determines if the given requirement String or Gem::Requirement is # satisfied by this version. # # Examples: # # Dionysus::VersionString.new('1.6.7').satisfies? '~> 1.6.0' => true # Dionysus::VersionString.new('1.6.7').satisfies? Gem::Requirement('< 1.6') => false # # See http://rubygems.rubyforge.org/rubygems-update/Gem/Requirement.html def satisfies?( requirement ) requirement = requirement.dup if requirement.is_a?(String) or requirement.is_a?(Gem::Requirement) requirement = Gem::Requirement.create(requirement) else raise ArgumentError, "Can only compare to a String or Gem::Requirement" end requirement.satisfied_by?(to_rubygem_version) end ## # Converts this VersionString into a Gem::Version def to_rubygem_version @rubygem_version ||= Gem::Version.create(self) end alias_method :to_gem_version, :to_rubygem_version ## # Indicates whether this VersionString is a prerelease. # # See http://rubygems.rubyforge.org/rubygems-update/Gem/Version.html#method-i-prerelease%3F def prerelease?() to_rubygem_version.prerelease?; end end end silence_warnings do RUBY_VERSION = Dionysus::VersionString.new(RUBY_VERSION) end