Sha256: c0b76b5b6b2cb34cb714a8cbcc7ae0462f959a4d0bef6fb400e0cb34033b54b7
Contents?: true
Size: 985 Bytes
Versions: 16
Compression:
Stored size: 985 Bytes
Contents
module ActsAsArchive module Base module Restore def self.included(base) unless base.included_modules.include?(InstanceMethods) base.send :extend, ClassMethods base.send :include, InstanceMethods end end module ClassMethods def copy_from_archive(conditions) add_conditions!(where = '', conditions) col_names = column_names - [ 'deleted_at' ] col_names.map! { |col| connection.quote_column_name(col) } connection.execute(%{ INSERT INTO #{table_name} (#{col_names.join(', ')}) SELECT #{col_names.join(', ')} FROM archived_#{table_name} #{where} }) connection.execute("DELETE FROM archived_#{table_name} #{where}") end def restore_all(conditions=nil) copy_from_archive(conditions) end end module InstanceMethods end end end end
Version data entries
16 entries across 16 versions & 6 rubygems