Module: Archivist::Migration::ClassMethods

Defined in:
lib/archivist/migration.rb

Instance Method Summary collapse

Instance Method Details

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/archivist/migration.rb', line 16

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