# File lib/archivist/base.rb, line 166 def copy_from_archive(conditions,delete=true) where = sanitize_sql(conditions) where = where.gsub("#{table_name}","archived_#{table_name}") unless where.nil? || where =~ /archived/ unless where == "" found = self::Archive.where(where) else found = self::Archive.all end found.each do |m| self.transaction do my_attribute_names = self.new.attribute_names #this should be Hash.select but 1.8.7 returns an array from select but a hash from reject... dumb attrs = m.attributes.reject{|k,v| !my_attribute_names.include?(k.to_s)} if self.where(:id=>m.id).empty? new_m = self.create(attrs) connection.execute(%{UPDATE #{table_name} SET #{self.primary_key} = #{m.id} WHERE #{self.primary_key} = #{new_m.id} }) else self.where(:id=>m.id).first.update_attributes(attrs) end m.destroy if delete end end end
# File lib/archivist/base.rb, line 156 def copy_to_archive(conditions,delete=true,&block) where = sanitize_sql(conditions) found = self.where(where) found.each do |m| result = m.copy_self_to_archive(&block) m.destroy! if delete && result end end
Generated with the Darkfish Rdoc Generator 2.