Module: Paperclip::Schema::Statements

Includes:
DeprecationHelper
Defined in:
lib/paperclip/schema.rb

Instance Method Summary collapse

Instance Method Details

#add_attachment(table_name, *attachment_names) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/paperclip/schema.rb', line 40

def add_attachment(table_name, *attachment_names)
  if attachment_names.empty?
    raise ArgumentError, "Please specify attachment name in your add_attachment call in your migration."
  end

  options = attachment_names.extract_options!

  attachment_names.each do |attachment_name|
    COLUMNS.each_pair do |column_name, column_type|
      column_options = Schema.column_options(options, column_name)
      add_column(table_name, "#{attachment_name}_#{column_name}", column_type, **column_options)
    end
  end
end

#drop_attached_file(*args) ⇒ Object



67
68
69
70
# File 'lib/paperclip/schema.rb', line 67

def drop_attached_file(*args)
  deprecation_warn "Method `drop_attached_file` in the migration has been deprecated and will be replaced by `remove_attachment`."
  remove_attachment(*args)
end

#remove_attachment(table_name, *attachment_names) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/paperclip/schema.rb', line 55

def remove_attachment(table_name, *attachment_names)
  if attachment_names.empty?
    raise ArgumentError, "Please specify attachment name in your remove_attachment call in your migration."
  end

  attachment_names.each do |attachment_name|
    COLUMNS.keys.each do |column_name|
      remove_column(table_name, "#{attachment_name}_#{column_name}")
    end
  end
end