Introduce Rails.gem_version

This method return `Gem::Version.new(Rails.version)`, suggesting a more
reliable way to perform version comparison.

Example:

    Rails.version #=> "4.1.2"
    Rails.gem_version #=> #<Gem::Version "4.1.2">

    Rails.version > "4.1.10" #=> false
    Rails.gem_version > Gem::Version.new("4.1.10") #=> true
    Gem::Requirement.new("~> 4.1.2") =~ Rails.gem_version #=> true

This was originally introduced as `.version` by @charliesome in #8501
but got reverted in #10002 since it was not backward compatible.

Also, updating template for `rake update_versions`.
This commit is contained in:
Prem Sichanugrist 2014-02-18 16:13:23 -05:00
parent 058d3c6183
commit 2dd2fcf896
No known key found for this signature in database
GPG Key ID: EA07121A64B02AD9
19 changed files with 173 additions and 60 deletions

@ -66,7 +66,7 @@ task :update_versions do
version_file = File.read("version.rb")
PROJECTS.each do |project|
Dir["#{project}/lib/*/version.rb"].each do |file|
Dir["#{project}/lib/*/gem_version.rb"].each do |file|
File.open(file, "w") do |f|
f.write version_file.gsub(/Rails/, constants[project])
end

@ -0,0 +1,15 @@
module ActionMailer
# Returns the version of the currently loaded ActionMailer as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,11 +1,8 @@
module ActionMailer
# Returns the version of the currently loaded ActionMailer as a Gem::Version
def self.version
Gem::Version.new "4.2.0.alpha"
end
require_relative 'gem_version'
module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActionMailer.version.segments
STRING = ActionMailer.version.to_s
module ActionMailer
# Returns the version of the currently loaded ActionMailer as a <tt>Gem::Version</tt>
def self.version
gem_version
end
end

@ -0,0 +1,15 @@
module ActionPack
# Returns the version of the currently loaded ActionPack as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,11 +1,8 @@
module ActionPack
# Returns the version of the currently loaded ActionPack as a Gem::Version
def self.version
Gem::Version.new "4.2.0.alpha"
end
require_relative 'gem_version'
module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActionPack.version.segments
STRING = ActionPack.version.to_s
module ActionPack
# Returns the version of the currently loaded ActionPack as a <tt>Gem::Version</tt>
def self.version
gem_version
end
end

@ -0,0 +1,15 @@
module ActionView
# Returns the version of the currently loaded ActionView as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,11 +1,8 @@
module ActionView
# Returns the version of the currently loaded ActionView as a Gem::Version
def self.version
Gem::Version.new "4.2.0.alpha"
end
require_relative 'gem_version'
module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActionView.version.segments
STRING = ActionView.version.to_s
module ActionView
# Returns the version of the currently loaded ActionView as a <tt>Gem::Version</tt>
def self.version
gem_version
end
end

@ -0,0 +1,15 @@
module ActiveModel
# Returns the version of the currently loaded ActiveModel as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,11 +1,8 @@
module ActiveModel
# Returns the version of the currently loaded ActiveModel as a Gem::Version
def self.version
Gem::Version.new "4.2.0.alpha"
end
require_relative 'gem_version'
module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActiveModel.version.segments
STRING = ActiveModel.version.to_s
module ActiveModel
# Returns the version of the currently loaded ActiveModel as a <tt>Gem::Version</tt>
def self.version
gem_version
end
end

@ -0,0 +1,15 @@
module ActiveRecord
# Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,11 +1,8 @@
module ActiveRecord
# Returns the version of the currently loaded ActiveRecord as a Gem::Version
def self.version
Gem::Version.new "4.2.0.alpha"
end
require_relative 'gem_version'
module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActiveRecord.version.segments
STRING = ActiveRecord.version.to_s
module ActiveRecord
# Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
def self.version
gem_version
end
end

@ -0,0 +1,15 @@
module ActiveSupport
# Returns the version of the currently loaded ActiveSupport as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,11 +1,8 @@
module ActiveSupport
# Returns the version of the currently loaded ActiveSupport as a Gem::Version
def self.version
Gem::Version.new "4.2.0.alpha"
end
require_relative 'gem_version'
module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActiveSupport.version.segments
STRING = ActiveSupport.version.to_s
module ActiveSupport
# Returns the version of the currently loaded ActiveSupport as a <tt>Gem::Version</tt>
def self.version
gem_version
end
end

@ -1,3 +1,18 @@
* Introduce `Rails.gem_version` as a convenience method to return
`Gem::Version.new(Rails.version)`, suggesting a more reliable way to perform
version comparison.
Example:
Rails.version #=> "4.1.2"
Rails.gem_version #=> #<Gem::Version "4.1.2">
Rails.version > "4.1.10" #=> false
Rails.gem_version > Gem::Version.new("4.1.10") #=> true
Gem::Requirement.new("~> 4.1.2") =~ Rails.gem_version #=> true
*Prem Sichanugrist*
* Avoid namespacing routes inside engines.
Mountable engines are namespaced by default so the generated routes

@ -80,10 +80,6 @@ def groups(*groups)
groups
end
def version
VERSION::STRING
end
def public_path
application && Pathname.new(application.paths["public"].first)
end

@ -0,0 +1,15 @@
module Rails
# Returns the version of the currently loaded Rails as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end

@ -1,10 +1,8 @@
module Rails
module VERSION
MAJOR = 4
MINOR = 2
TINY = 0
PRE = "alpha"
require_relative 'gem_version'
STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
module Rails
# Returns the version of the currently loaded Rails as a string.
def self.version
VERSION::STRING
end
end

@ -0,0 +1,12 @@
require 'abstract_unit'
class VersionTest < ActiveSupport::TestCase
def test_rails_version_returns_a_string
assert Rails.version.is_a? String
end
def test_rails_gem_version_returns_a_correct_gem_version_object
assert Rails.gem_version.is_a? Gem::Version
assert_equal Rails.version, Rails.gem_version.to_s
end
end

@ -1,4 +1,9 @@
module Rails
# Returns the version of the currently loaded Rails as a <tt>Gem::Version</tt>
def self.gem_version
Gem::Version.new VERSION::STRING
end
module VERSION
MAJOR = 4
MINOR = 2