Skip to content
This repository
Browse code

Merge pull request #8501 from charliesome/version-to-s

Add #to_s method to VERSION modules
  • Loading branch information...
commit e600384515dc06db2c56ff5be5c18779f7b379a5 2 parents e96fa89 + 8f05fee
Rafael Mendonça França authored March 23, 2013
2  Rakefile
@@ -141,7 +141,7 @@ task :update_versions do
141 141
   require File.dirname(__FILE__) + "/version"
142 142
 
143 143
   File.open("RAILS_VERSION", "w") do |f|
144  
-    f.write Rails::VERSION::STRING + "\n"
  144
+    f.puts Rails.version
145 145
   end
146 146
 
147 147
   constants = {
13  actionmailer/lib/action_mailer/version.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module ActionMailer
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  # Returns the version of the currently loaded ActionMailer as a Gem::Version
  3
+  def self.version
  4
+    Gem::Version.new "4.0.0.beta1"
  5
+  end
7 6
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  7
+  module VERSION #:nodoc:
  8
+    MAJOR, MINOR, TINY, PRE = ActionMailer.version.segments
  9
+    STRING = ActionMailer.version.to_s
9 10
   end
10 11
 end
13  actionpack/lib/action_pack/version.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module ActionPack
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  # Returns the version of the currently loaded ActionPack as a Gem::Version
  3
+  def self.version
  4
+    Gem::Version.new "4.0.0.beta1"
  5
+  end
7 6
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  7
+  module VERSION #:nodoc:
  8
+    MAJOR, MINOR, TINY, PRE = ActionPack.version.segments
  9
+    STRING = ActionPack.version.to_s
9 10
   end
10 11
 end
13  activemodel/lib/active_model/version.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module ActiveModel
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  # Returns the version of the currently loaded ActiveModel as a Gem::Version
  3
+  def self.version
  4
+    Gem::Version.new "4.0.0.beta1"
  5
+  end
7 6
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  7
+  module VERSION #:nodoc:
  8
+    MAJOR, MINOR, TINY, PRE = ActiveModel.version.segments
  9
+    STRING = ActiveModel.version.to_s
9 10
   end
10 11
 end
13  activerecord/lib/active_record/version.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module ActiveRecord
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  # Returns the version of the currently loaded ActiveRecord as a Gem::Version
  3
+  def self.version
  4
+    Gem::Version.new "4.0.0.beta1"
  5
+  end
7 6
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  7
+  module VERSION #:nodoc:
  8
+    MAJOR, MINOR, TINY, PRE = ActiveRecord.version.segments
  9
+    STRING = ActiveRecord.version.to_s
9 10
   end
10 11
 end
13  activesupport/lib/active_support/version.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module ActiveSupport
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  # Returns the version of the currently loaded ActiveSupport as a Gem::Version
  3
+  def self.version
  4
+    Gem::Version.new "4.0.0.beta1"
  5
+  end
7 6
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  7
+  module VERSION #:nodoc:
  8
+    MAJOR, MINOR, TINY, PRE = ActiveSupport.version.segments
  9
+    STRING = ActiveSupport.version.to_s
9 10
   end
10 11
 end
4  railties/CHANGELOG.md
Source Rendered
... ...
@@ -1,5 +1,9 @@
1 1
 ## Rails 4.0.0 (unreleased) ##
2 2
 
  3
+*   `Rails.version` now returns an instance of `Gem::Version`
  4
+
  5
+    *Charlie Somerville*
  6
+
3 7
 *   Don't generate a scaffold.css when --no-assets is specified
4 8
 
5 9
     *Kevin Glowacz*
4  railties/lib/rails.rb
@@ -82,10 +82,6 @@ def groups(*groups)
82 82
       groups
83 83
     end
84 84
 
85  
-    def version
86  
-      VERSION::STRING
87  
-    end
88  
-
89 85
     def public_path
90 86
       application && Pathname.new(application.paths["public"].first)
91 87
     end
2  railties/lib/rails/commands/application.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require 'rails/version'
2 2
 
3 3
 if ['--version', '-v'].include?(ARGV.first)
4  
-  puts "Rails #{Rails::VERSION::STRING}"
  4
+  puts "Rails #{Rails.version}"
5 5
   exit(0)
6 6
 end
7 7
 
4  railties/lib/rails/generators/app_base.rb
... ...
@@ -1,7 +1,7 @@
1 1
 require 'digest/md5'
2 2
 require 'securerandom'
3 3
 require 'active_support/core_ext/string/strip'
4  
-require 'rails/version' unless defined?(Rails::VERSION)
  4
+require 'rails/version' unless defined?(Rails.version)
5 5
 require 'rbconfig'
6 6
 require 'open-uri'
7 7
 require 'uri'
@@ -142,7 +142,7 @@ def rails_gemfile_entry
142 142
         else
143 143
           <<-GEMFILE.strip_heredoc
144 144
             # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
145  
-            gem 'rails', '#{Rails::VERSION::STRING}'
  145
+            gem 'rails', '#{Rails.version}'
146 146
           GEMFILE
147 147
         end
148 148
       end
2  railties/lib/rails/generators/rails/plugin_new/templates/%name%.gemspec
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18 18
   s.test_files = Dir["test/**/*"]
19 19
 <% end -%>
20 20
 
21  
-  <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails::VERSION::STRING %>"
  21
+  <%= '# ' if options.dev? || options.edge? -%>s.add_dependency "rails", "~> <%= Rails.version %>"
22 22
 <% unless options[:skip_active_record] -%>
23 23
 
24 24
   s.add_development_dependency "<%= gem_for_database %>"
2  railties/lib/rails/generators/rails/plugin_new/templates/Gemfile
... ...
@@ -1,7 +1,7 @@
1 1
 source "https://rubygems.org"
2 2
 
3 3
 <% if options[:skip_gemspec] -%>
4  
-<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails::VERSION::STRING %>"
  4
+<%= '# ' if options.dev? || options.edge? -%>gem "rails", "~> <%= Rails.version %>"
5 5
 <% else -%>
6 6
 # Declare your gem's dependencies in <%= name %>.gemspec.
7 7
 # Bundler will treat runtime dependencies like base dependencies, and
4  railties/lib/rails/info.rb
@@ -29,7 +29,7 @@ def frameworks
29 29
       def framework_version(framework)
30 30
         if Object.const_defined?(framework.classify)
31 31
           require "#{framework}/version"
32  
-          "#{framework.classify}::VERSION::STRING".constantize
  32
+          framework.classify.constantize.version.to_s
33 33
         end
34 34
       end
35 35
 
@@ -75,7 +75,7 @@ def to_html
75 75
 
76 76
     # The Rails version.
77 77
     property 'Rails version' do
78  
-      Rails::VERSION::STRING
  78
+      Rails.version.to_s
79 79
     end
80 80
 
81 81
     property 'JavaScript Runtime' do
13  railties/lib/rails/version.rb
... ...
@@ -1,10 +1,11 @@
1 1
 module Rails
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  # Returns the version of the currently loaded Rails as a Gem::Version
  3
+  def self.version
  4
+    Gem::Version.new "4.0.0.beta1"
  5
+  end
7 6
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  7
+  module VERSION #:nodoc:
  8
+    MAJOR, MINOR, TINY, PRE = Rails.version.segments
  9
+    STRING = Rails.version.to_s
9 10
   end
10 11
 end
4  railties/test/generators/plugin_new_generator_test.rb
@@ -292,7 +292,7 @@ def test_skipping_gemspec
292 292
     assert_no_file "bukkits.gemspec"
293 293
     assert_file "Gemfile" do |contents|
294 294
       assert_no_match('gemspec', contents)
295  
-      assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents)
  295
+      assert_match(/gem "rails", "~> #{Rails.version}"/, contents)
296 296
       assert_match(/group :development do\n  gem "sqlite3"\nend/, contents)
297 297
       assert_no_match(/# gem "jquery-rails"/, contents)
298 298
     end
@@ -303,7 +303,7 @@ def test_skipping_gemspec_in_full_mode
303 303
     assert_no_file "bukkits.gemspec"
304 304
     assert_file "Gemfile" do |contents|
305 305
       assert_no_match('gemspec', contents)
306  
-      assert_match(/gem "rails", "~> #{Rails::VERSION::STRING}"/, contents)
  306
+      assert_match(/gem "rails", "~> #{Rails.version}"/, contents)
307 307
       assert_match(/group :development do\n  gem "sqlite3"\nend/, contents)
308 308
     end
309 309
   end
2  railties/test/rails_info_test.rb
@@ -38,7 +38,7 @@ def test_property_with_block
38 38
   end
39 39
 
40 40
   def test_framework_version
41  
-    assert_property 'Active Support version', ActiveSupport::VERSION::STRING
  41
+    assert_property 'Active Support version', ActiveSupport.version
42 42
   end
43 43
 
44 44
   def test_frameworks_exist
12  version.rb
... ...
@@ -1,10 +1,10 @@
1 1
 module Rails
2  
-  module VERSION #:nodoc:
3  
-    MAJOR = 4
4  
-    MINOR = 0
5  
-    TINY  = 0
6  
-    PRE   = "beta1"
  2
+  def self.version
  3
+    Gem::Version.new "4.0.0.beta1"
  4
+  end
7 5
 
8  
-    STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
  6
+  module VERSION #:nodoc:
  7
+    MAJOR, MINOR, TINY, PRE = Rails.version.segments
  8
+    STRING = Rails.version.to_s
9 9
   end
10 10
 end

0 notes on commit e600384

Please sign in to comment.
Something went wrong with that request. Please try again.