diff options
author | yui-knk <spiketeika@gmail.com> | 2016-03-28 00:49:43 +0900 |
---|---|---|
committer | Jeremy Daer <jeremydaer@gmail.com> | 2016-04-29 15:10:03 -0700 |
commit | 7fc4979d4dab63591dcbf75367c496cbfa2881ce (patch) | |
tree | acbf4d9137bd73b87dc90e844f12d497824dd085 /activerecord/lib | |
parent | bbb84a17213d60f25a61ae4a09111d5adac01a05 (diff) | |
download | rails-7fc4979d4dab63591dcbf75367c496cbfa2881ce.tar.gz rails-7fc4979d4dab63591dcbf75367c496cbfa2881ce.tar.bz2 rails-7fc4979d4dab63591dcbf75367c496cbfa2881ce.zip |
Migrations: move version-finding responsibility
`ActiveRecord::Migration` needn't know about migration version
compatibility lookup. Delegate it to the Compatibility module.
Signed-off-by: Jeremy Daer <jeremydaer@gmail.com>
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/migration.rb | 8 | ||||
-rw-r--r-- | activerecord/lib/active_record/migration/compatibility.rb | 10 |
2 files changed, 11 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/migration.rb b/activerecord/lib/active_record/migration.rb index 99a79024ad..33c236a732 100644 --- a/activerecord/lib/active_record/migration.rb +++ b/activerecord/lib/active_record/migration.rb @@ -524,13 +524,7 @@ module ActiveRecord end def self.[](version) - version = version.to_s - name = "V#{version.tr('.', '_')}" - unless Compatibility.const_defined?(name) - versions = Compatibility.constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect } - raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}" - end - Compatibility.const_get(name) + Compatibility.find(version) end def self.current_version diff --git a/activerecord/lib/active_record/migration/compatibility.rb b/activerecord/lib/active_record/migration/compatibility.rb index a20d7e0820..69bd9ff1cf 100644 --- a/activerecord/lib/active_record/migration/compatibility.rb +++ b/activerecord/lib/active_record/migration/compatibility.rb @@ -1,6 +1,16 @@ module ActiveRecord class Migration module Compatibility # :nodoc: all + def self.find(version) + version = version.to_s + name = "V#{version.tr('.', '_')}" + unless const_defined?(name) + versions = constants.grep(/\AV[0-9_]+\z/).map { |s| s.to_s.delete('V').tr('_', '.').inspect } + raise ArgumentError, "Unknown migration version #{version.inspect}; expected one of #{versions.sort.join(', ')}" + end + const_get(name) + end + V5_0 = Current module FourTwoShared |