diff options
author | Prem Sichanugrist <s@sikac.hu> | 2014-02-18 16:13:23 -0500 |
---|---|---|
committer | Prem Sichanugrist <s@sikac.hu> | 2014-03-05 12:37:38 -0500 |
commit | 2dd2fcf89673afbcf95240ecebaf34826a195164 (patch) | |
tree | 238825fa3198c023afb6545693bfbedff6d917d8 /activemodel | |
parent | 058d3c6183ef6e0e878bea37f4fe3f8f0d6758e2 (diff) | |
download | rails-2dd2fcf89673afbcf95240ecebaf34826a195164.tar.gz rails-2dd2fcf89673afbcf95240ecebaf34826a195164.tar.bz2 rails-2dd2fcf89673afbcf95240ecebaf34826a195164.zip |
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`.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/lib/active_model/gem_version.rb | 15 | ||||
-rw-r--r-- | activemodel/lib/active_model/version.rb | 11 |
2 files changed, 19 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/gem_version.rb b/activemodel/lib/active_model/gem_version.rb new file mode 100644 index 0000000000..964b24398d --- /dev/null +++ b/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 = 2 + TINY = 0 + PRE = "alpha" + + STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".") + end +end diff --git a/activemodel/lib/active_model/version.rb b/activemodel/lib/active_model/version.rb index 5c9d2bc6bc..b1f9082ea7 100644 --- a/activemodel/lib/active_model/version.rb +++ b/activemodel/lib/active_model/version.rb @@ -1,11 +1,8 @@ +require_relative 'gem_version' + 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 - Gem::Version.new "4.2.0.alpha" - end - - module VERSION #:nodoc: - MAJOR, MINOR, TINY, PRE = ActiveModel.version.segments - STRING = ActiveModel.version.to_s + gem_version end end |