module ArCache::ActiveRecord::ConnectionAdapters::DatabaseStatements
Public Instance Methods
delete(arel, ...)
click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 42 def delete(arel, ...) super.tap { |num| update_ar_cache(arel) unless num.zero? } end
insert(arel, ...)
click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 23 def insert(arel, ...) super.tap do if arel.is_a?(String) sql = arel.downcase ArCache::Table.all.each do |table| transaction_manager.add_transaction_table(table.name) if sql.include?(table.name) end else transaction_manager.add_transaction_table(arel.ast.relation.name) end end end
Also aliased as: create
select_all(arel, ...)
click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 7 def select_all(arel, ...) result = super klass, select_values = arel.try(:klass_and_select_values) return result if klass.nil? klass.ar_cache_table.write(result.to_a) if select_values result.to_a.each { |r| r.slice!(*select_values) } elsif klass.ignored_columns.any? result.to_a.each { |r| r.except!(*klass.ignored_columns) } end result end
truncate(table_name, ...)
click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 46 def truncate(table_name, ...) super.tap { update_ar_cache_by_table(table_name) } end
truncate_tables(*table_names)
click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 50 def truncate_tables(*table_names) super.tap do table_names.each { |table_name| update_ar_cache_by_table(table_name) } end end
update(arel, ...)
click to toggle source
Calls superclass method
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 38 def update(arel, ...) super.tap { |num| update_ar_cache(arel) unless num.zero? } end
Private Instance Methods
update_ar_cache(arel_or_sql_string)
click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 56 def update_ar_cache(arel_or_sql_string) if arel_or_sql_string.is_a?(String) update_ar_cache_by_sql(arel_or_sql_string) else # is Arel::TreeManager update_ar_cache_by_arel(arel_or_sql_string) end end
update_ar_cache_by_arel(arel)
click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 64 def update_ar_cache_by_arel(arel) return if ArCache.skip_expire? arel_table = arel.ast.relation.is_a?(Arel::Table) ? arel.ast.relation : arel.ast.relation.left klass = arel_table.instance_variable_get(:@klass) current_transaction.update_ar_cache_table(klass.ar_cache_table) end
update_ar_cache_by_sql(sql)
click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 72 def update_ar_cache_by_sql(sql) sql = sql.downcase ArCache::Table.all.each do |table| current_transaction.update_ar_cache_table(table) if sql.include?(table.name) end end
update_ar_cache_by_table(table_name)
click to toggle source
# File lib/ar_cache/active_record/connection_adapters/abstract/database_statements.rb, line 80 def update_ar_cache_by_table(table_name) ArCache::Table.all.each do |table| break current_transaction.update_ar_cache_table(table) if table_name == table.name end end