module ActsAsArchive module Base def self.included(base) base.extend ActMethods end module ActMethods def acts_as_archive(options={}) class_eval <<-end_eval def self.acts_as_archive? self.to_s == #{self.to_s.inspect} end def self.archive_indexes #{Array(options[:indexes]).collect(&:to_s).inspect} end if self.descends_from_active_record? class Archive < ActiveRecord::Base self.record_timestamps = false self.table_name = "archived_#{self.table_name}" def self.sti_name "#{self.sti_name}" end def restore #{self.base_class.to_s}.restore_all([ 'id = ?', id ]) @destroyed = true freeze end protected def self.compute_type(type_name) modularized_name = type_name_with_module(type_name) silence_warnings do begin class_eval(modularized_name+"::Archive", __FILE__) rescue NameError class_eval(type_name+"::Archive", __FILE__) end end end end else class Archive < self.superclass::Archive self.record_timestamps = false self.table_name = "archived_#{self.table_name}" def self.sti_name "#{self.sti_name}" end def restore #{self.base_class.to_s}.restore_all([ 'id = ?', id ]) @destroyed = true freeze end protected def self.compute_type(type_name) modularized_name = type_name_with_module(type_name) silence_warnings do begin class_eval(modularized_name+"::Archive", __FILE__) rescue NameError class_eval(type_name+"::Archive", __FILE__) end end end end end end_eval include Destroy include Restore include Table end end end end