Class: LowCardTables::VersionSupport
- Inherits:
-
Object
- Object
- LowCardTables::VersionSupport
- Defined in:
- lib/low_card_tables/version_support.rb
Overview
Contains methods used by the codebase to support differing ActiveRecord versions. This is just a clean way of factoring out differing ActiveRecord API into a single class.
Class Method Summary collapse
-
.clear_schema_cache!(model) ⇒ Object
Clear the schema cache for a given model.
-
.default_scopes_accept_a_block? ⇒ Boolean
Can you specify a block on default_scope? This was added in ActiveRecord 3.1.
-
.define_default_scope(klass, conditions) ⇒ Object
Define a default scope on the class in question.
-
.migrate_is_a_class_method? ⇒ Boolean
Is #migrate a class method, or an instance method, on ActiveRecord::Migration? It changed to an instance method as of ActiveRecord 3.1.
Class Method Details
.clear_schema_cache!(model) ⇒ Object
Clear the schema cache for a given model.
7 8 9 10 11 12 13 |
# File 'lib/low_card_tables/version_support.rb', line 7 def clear_schema_cache!(model) if model.connection.respond_to?(:schema_cache) model.connection.schema_cache.clear! elsif model.connection.respond_to?(:clear_cache!) model.connection.clear_cache! end end |
.default_scopes_accept_a_block? ⇒ Boolean
Can you specify a block on default_scope? This was added in ActiveRecord 3.1.
16 17 18 |
# File 'lib/low_card_tables/version_support.rb', line 16 def default_scopes_accept_a_block? ! (::ActiveRecord::VERSION::MAJOR <= 3 && ::ActiveRecord::VERSION::MINOR == 0) end |
.define_default_scope(klass, conditions) ⇒ Object
Define a default scope on the class in question. This is only actually used from our specs.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/low_card_tables/version_support.rb', line 27 def define_default_scope(klass, conditions) if default_scopes_accept_a_block? if conditions klass.instance_eval %{ default_scope { where(#{conditions.inspect}) } } else klass.instance_eval %{ default_scope { } } end else if conditions klass.instance_eval %{ default_scope where(#{conditions.inspect}) } else klass.instance_eval %{ default_scope nil } end end end |
.migrate_is_a_class_method? ⇒ Boolean
Is #migrate a class method, or an instance method, on ActiveRecord::Migration? It changed to an instance method as of ActiveRecord 3.1.
22 23 24 |
# File 'lib/low_card_tables/version_support.rb', line 22 def migrate_is_a_class_method? (::ActiveRecord::VERSION::MAJOR <= 3 && ::ActiveRecord::VERSION::MINOR == 0) end |