Module: Cropper::Schema::Statements

Defined in:
lib/cropper/schema.rb

Instance Method Summary collapse

Instance Method Details

#add_upload(table_name, *attachment_names) ⇒ Object

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cropper/schema.rb', line 25

def add_upload(table_name, *attachment_names)
  raise ArgumentError, "Please specify attachment name in your add_upload call in your migration." if attachment_names.empty?
  
  attachment_names.each do |attachment_name|
    UPLOAD_COLUMNS.each_pair do |column_name, column_type|
      unless column_exists? table_name, "#{attachment_name}_#{column_name}"
        add_column(table_name, "#{attachment_name}_#{column_name}", column_type)
      end
    end
  end
end

#remove_upload(table_name, *attachment_names) ⇒ Object

Raises:

  • (ArgumentError)


38
39
40
41
42
43
44
45
46
47
48
# File 'lib/cropper/schema.rb', line 38

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

  attachment_names.each do |attachment_name|
    COLUMNS.each_pair do |column_name, column_type|
      if column_exists? table_name, "#{attachment_name}_#{column_name}"
        remove_column(table_name, "#{attachment_name}_#{column_name}")
      end
    end
  end
end