Module: ActiveRecord::Turntable::Compatibility
- Included in:
- ActiveRecordExt::AbstractAdapter, ActiveRecordExt::Persistence, ActiveRecordExt::QueryCache::ClassMethods
- Defined in:
- lib/active_record/turntable/compatibility.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](version = ActiveRecord.gem_version.release) ⇒ Object (also: #compatible_module)
- #compatible_versions ⇒ Object
- #find_compatible_module(version) ⇒ Object
- #find_compatible_version(version) ⇒ Object
Class Method Details
.extended(base) ⇒ Object
3 4 5 |
# File 'lib/active_record/turntable/compatibility.rb', line 3 def self.extended(base) base.instance_variable_set(:@_compatible_versions, []) end |
Instance Method Details
#[](version = ActiveRecord.gem_version.release) ⇒ Object Also known as: compatible_module
7 8 9 10 11 12 |
# File 'lib/active_record/turntable/compatibility.rb', line 7 def [](version = ActiveRecord.gem_version.release) unless version.is_a?(Gem::Version) version = Gem::Version.new(version) end find_compatible_module(version) end |
#compatible_versions ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/active_record/turntable/compatibility.rb', line 31 def compatible_versions if @_compatible_versions.empty? @_compatible_versions = constants.map do |const| /^V(?<major>\d+)(_(?<minor>\d+)(_(?<teeny>\d))?)?/ =~ const nil unless major Gem::Version.new([major, minor, teeny].compact.join(".")) end @_compatible_versions.compact! @_compatible_versions.sort! end @_compatible_versions end |
#find_compatible_module(version) ⇒ Object
15 16 17 18 |
# File 'lib/active_record/turntable/compatibility.rb', line 15 def find_compatible_module(version) module_version = find_compatible_version(version) const_get("V#{module_version.to_s.tr(".", "_")}") end |
#find_compatible_version(version) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/active_record/turntable/compatibility.rb', line 20 def find_compatible_version(version) target_version = nil compatible_versions.each do |compatible_version| break if version < compatible_version target_version = compatible_version end target_version end |