Skip to content

Commit

Permalink
Preparing for big rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
winton committed Dec 11, 2010
1 parent e9cd7b6 commit 34ae418
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 804 deletions.
70 changes: 53 additions & 17 deletions lib/acts_as_archive.rb
Expand Up @@ -4,31 +4,67 @@

$:.unshift File.dirname(__FILE__) + '/acts_as_archive'

require 'base'
require 'base/adapters/mysql'
require 'base/adapters/postgresql'
require 'base/destroy'
require 'base/restore'
require 'base/table'
require 'migration'
require 'version'

module ActsAsArchive

def self.update(*models)
models.each do |klass|
if klass.respond_to?(:acts_as_archive?) && klass.acts_as_archive?
time = Benchmark.measure do
klass.create_archive_table
klass.migrate_from_acts_as_paranoid
klass.create_archive_indexes
def self.migrate_from_acts_as_paranoid(klass)
if respond_to?(:acts_as_archive?) && acts_as_archive?
time = Benchmark.measure do
if column_names.include?('deleted_at')
if table_exists? && archive_table_exists?
condition = "deleted_at IS NOT NULL"
if self.count_by_sql("SELECT COUNT(*) FROM #{table_name} WHERE #{condition}") > 0
self.move_to(
Archive,
:conditions => condition,
:migrate => true
)
end
end
end
$stdout.puts "-- ActsAsArchive.update(#{models.join(', ')})"
$stdout.puts " -> #{"%.4fs" % time.real}"
end
$stdout.puts "-- ActsAsArchive.update(#{models.join(', ')})"
$stdout.puts " -> #{"%.4fs" % time.real}"
end
end

module Base
def self.included(base)
base.extend ActMethods
end

module ActMethods
def acts_as_archive(options={})
end
end
end

module AbstractAdapter
def self.included(base)
unless base.included_modules.include?(InstanceMethods)
base.send :extend, ClassMethods
base.class_eval do
class <<self
unless method_defined?(:delete_sql_without_archive)
alias_method :delete_sql_without_archive, :delete_sql
alias_method :delete_sql, :delete_sql_with_archive
end
end
end
end
end

module ClassMethods
def delete_sql_with_archive(sql, name = nil)
delete_sql_without_archive(sql, name)
end
end

module InstanceMethods
end
end
end

ActiveRecord::Base.send(:include, ActsAsArchive::Base)
ActiveRecord::Migration.send(:include, ActsAsArchive::Migration)
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, ActsAsArchive::AbstractAdapter)
31 changes: 0 additions & 31 deletions lib/acts_as_archive/base.rb

This file was deleted.

17 changes: 0 additions & 17 deletions lib/acts_as_archive/base/adapters/mysql.rb

This file was deleted.

40 changes: 0 additions & 40 deletions lib/acts_as_archive/base/adapters/postgresql.rb

This file was deleted.

71 changes: 0 additions & 71 deletions lib/acts_as_archive/base/destroy.rb

This file was deleted.

36 changes: 0 additions & 36 deletions lib/acts_as_archive/base/restore.rb

This file was deleted.

0 comments on commit 34ae418

Please sign in to comment.