Skip to content

Commit

Permalink
Merge pull request #14103 from sikachu/4-1-stable-fix-versioning-task
Browse files Browse the repository at this point in the history
Introduce `Rails.gem_version`
  • Loading branch information
jeremy committed Mar 5, 2014
2 parents 332a359 + 3bf87d7 commit ea8aba8
Show file tree
Hide file tree
Showing 19 changed files with 167 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -66,7 +66,7 @@ task :update_versions do
version_file = File.read("version.rb") version_file = File.read("version.rb")


PROJECTS.each do |project| 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| File.open(file, "w") do |f|
f.write version_file.gsub(/Rails/, constants[project]) f.write version_file.gsub(/Rails/, constants[project])
end end
Expand Down
15 changes: 15 additions & 0 deletions actionmailer/lib/action_mailer/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
11 changes: 4 additions & 7 deletions actionmailer/lib/action_mailer/version.rb
@@ -1,11 +1,8 @@
require_relative 'gem_version'

module ActionMailer module ActionMailer
# Returns the version of the currently loaded ActionMailer as a Gem::Version # Returns the version of the currently loaded ActionMailer as a <tt>Gem::Version</tt>
def self.version def self.version
Gem::Version.new "4.1.0.rc1" gem_version
end

module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActionMailer.version.segments
STRING = ActionMailer.version.to_s
end end
end end
15 changes: 15 additions & 0 deletions actionpack/lib/action_pack/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
11 changes: 4 additions & 7 deletions actionpack/lib/action_pack/version.rb
@@ -1,11 +1,8 @@
require_relative 'gem_version'

module ActionPack module ActionPack
# Returns the version of the currently loaded ActionPack as a Gem::Version # Returns the version of the currently loaded ActionPack as a <tt>Gem::Version</tt>
def self.version def self.version
Gem::Version.new "4.1.0.rc1" gem_version
end

module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActionPack.version.segments
STRING = ActionPack.version.to_s
end end
end end
15 changes: 15 additions & 0 deletions actionview/lib/action_view/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
11 changes: 4 additions & 7 deletions actionview/lib/action_view/version.rb
@@ -1,11 +1,8 @@
require_relative 'gem_version'

module ActionView module ActionView
# Returns the version of the currently loaded ActionView as a Gem::Version # Returns the version of the currently loaded ActionView as a <tt>Gem::Version</tt>
def self.version def self.version
Gem::Version.new "4.1.0.rc1" gem_version
end

module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActionView.version.segments
STRING = ActionView.version.to_s
end end
end end
15 changes: 15 additions & 0 deletions activemodel/lib/active_model/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
11 changes: 4 additions & 7 deletions activemodel/lib/active_model/version.rb
@@ -1,11 +1,8 @@
require_relative 'gem_version'

module ActiveModel module ActiveModel
# Returns the version of the currently loaded ActiveModel as a Gem::Version # Returns the version of the currently loaded ActiveModel as a <tt>Gem::Version</tt>
def self.version def self.version
Gem::Version.new "4.1.0.rc1" gem_version
end

module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActiveModel.version.segments
STRING = ActiveModel.version.to_s
end end
end end
15 changes: 15 additions & 0 deletions activerecord/lib/active_record/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
11 changes: 4 additions & 7 deletions activerecord/lib/active_record/version.rb
@@ -1,11 +1,8 @@
require_relative 'gem_version'

module ActiveRecord module ActiveRecord
# Returns the version of the currently loaded ActiveRecord as a Gem::Version # Returns the version of the currently loaded ActiveRecord as a <tt>Gem::Version</tt>
def self.version def self.version
Gem::Version.new "4.1.0.rc1" gem_version
end

module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActiveRecord.version.segments
STRING = ActiveRecord.version.to_s
end end
end end
15 changes: 15 additions & 0 deletions activesupport/lib/active_support/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
11 changes: 4 additions & 7 deletions activesupport/lib/active_support/version.rb
@@ -1,11 +1,8 @@
require_relative 'gem_version'

module ActiveSupport module ActiveSupport
# Returns the version of the currently loaded ActiveSupport as a Gem::Version # Returns the version of the currently loaded ActiveSupport as a <tt>Gem::Version</tt>
def self.version def self.version
Gem::Version.new "4.1.0.rc1" gem_version
end

module VERSION #:nodoc:
MAJOR, MINOR, TINY, PRE = ActiveSupport.version.segments
STRING = ActiveSupport.version.to_s
end end
end end
15 changes: 15 additions & 0 deletions railties/CHANGELOG.md
@@ -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*

* Do not crash when `config/secrets.yml` is empty. * Do not crash when `config/secrets.yml` is empty.


*Yves Senn* *Yves Senn*
Expand Down
4 changes: 0 additions & 4 deletions railties/lib/rails.rb
Expand Up @@ -80,10 +80,6 @@ def groups(*groups)
groups groups
end end


def version
VERSION::STRING
end

def public_path def public_path
application && Pathname.new(application.paths["public"].first) application && Pathname.new(application.paths["public"].first)
end end
Expand Down
15 changes: 15 additions & 0 deletions railties/lib/rails/gem_version.rb
@@ -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 = 1
TINY = 0
PRE = "rc1"

STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
end
end
12 changes: 5 additions & 7 deletions railties/lib/rails/version.rb
@@ -1,10 +1,8 @@
module Rails require_relative 'gem_version'
module VERSION
MAJOR = 4
MINOR = 1
TINY = 0
PRE = "rc1"


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
end end
12 changes: 12 additions & 0 deletions railties/test/version_test.rb
@@ -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
5 changes: 5 additions & 0 deletions version.rb
@@ -1,4 +1,9 @@
module Rails 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 module VERSION
MAJOR = 4 MAJOR = 4
MINOR = 1 MINOR = 1
Expand Down

0 comments on commit ea8aba8

Please sign in to comment.