lib/bundler/ruby_version.rb in bundler-1.12.6 vs lib/bundler/ruby_version.rb in bundler-1.13.0.pre.1

- old
+ new

@@ -36,10 +36,26 @@ output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby" output end + # @private + PATTERN = / + ruby\s + ([\d.]+) # ruby version + (?:p(\d+))? # optional patchlevel + (?:\s\((\S+)\s(.+)\))? # optional engine info + /xo + + # Returns a RubyVersion from the given string. + # @param [String] the version string to match. + # @return [RubyVersion,Nil] The version if the string is a valid RubyVersion + # description, and nil otherwise. + def self.from_string(string) + new($1, $2, $3, $4) if string =~ PATTERN + end + def single_version_string to_s(gem_version) end def ==(other) @@ -62,11 +78,11 @@ # The priority of attributes are # 1. engine # 2. ruby_version # 3. engine_version def diff(other) - raise ArgumentError, "Can only diff with a RubyVersion" unless other.is_a?(RubyVersion) + raise ArgumentError, "Can only diff with a RubyVersion, not a #{other.class}" unless other.is_a?(RubyVersion) if engine != other.engine && @input_engine [:engine, engine, other.engine] elsif versions.empty? || !matches?(versions, other.gem_version) [:version, versions_string(versions), versions_string(other.versions)] elsif @input_engine && !matches?(engine_versions, other.engine_gem_version) @@ -85,20 +101,30 @@ RUBY_ENGINE.dup else # not defined in ruby 1.8.7 "ruby" end + # :sob: mocking RUBY_VERSION breaks stuff on 1.8.7 + ruby_version = ENV.fetch("BUNDLER_SPEC_RUBY_VERSION") { RUBY_VERSION }.dup ruby_engine_version = case ruby_engine when "ruby" - RUBY_VERSION.dup + ruby_version when "rbx" Rubinius::VERSION.dup when "jruby" JRUBY_VERSION.dup else raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized" end - @ruby_version ||= RubyVersion.new(RUBY_VERSION.dup, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version) + @ruby_version ||= RubyVersion.new(ruby_version, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version) + end + + def to_gem_version_with_patchlevel + @gem_version_with_patch ||= begin + Gem::Version.create("#{@gem_version}.#{@patchlevel}") + rescue ArgumentError + @gem_version + end end private def matches?(requirements, version)