Module: ActsAsArchive::DatabaseStatements::InstanceMethods

Defined in:
lib/acts_as_archive.rb

Instance Method Summary collapse

Instance Method Details

#delete_sql_with_archive(sql, name = nil) ⇒ Object



206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/acts_as_archive.rb', line 206

def delete_sql_with_archive(sql, name = nil)
  @mutex ||= Mutex.new
  @mutex.synchronize do
    unless ActsAsArchive.disabled
      from, where = /DELETE FROM (.+)/i.match(sql)[1].split(/\s+WHERE\s+/i, 2)
      from = from.strip.gsub(/[`"]/, '').split(/\s*,\s*/)
  
      ActsAsArchive.find(from).each do |config|
        ActsAsArchive.move(config, where)
      end
    end
  end
  
  delete_sql_without_archive(sql, name)
end