Module: ActsAsArchive::Migration::ClassMethods

Defined in:
lib/acts_as_archive/migration.rb

Instance Method Summary collapse

Instance Method Details

#method_missing_with_archive(method, *arguments, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/acts_as_archive/migration.rb', line 20

def method_missing_with_archive(method, *arguments, &block)
  args = Marshal.load(Marshal.dump(arguments))
  method_missing_without_archive(method, *arguments, &block)
  supported = [
    :add_column, :add_timestamps, :change_column,
    :change_column_default, :change_table,
    :drop_table, :remove_column, :remove_columns,
    :remove_timestamps, :rename_column, :rename_table
  ]
  if args.include?(:deleted_at) || args.include?('deleted_at')
    # Don't change the archive's deleted_at column
    return
  end
  if !args.empty? && supported.include?(method)
    connection = ActiveRecord::Base.connection
    args[0] = "archived_" + ActiveRecord::Migrator.proper_table_name(args[0])
    if method == :rename_table
      args[1] = "archived_" + args[1].to_s
    end
    if connection.table_exists?(args[0])
      connection.send(method, *args, &block)
    end
  end
end