Module: PaperCropper::Schema::Statements

Defined in:
lib/paper_cropper/schema.rb

Overview

#########################################################################

Instance Method Summary collapse

Instance Method Details

#add_crop_attachment(table_name, *attachment_names) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/paper_cropper/schema.rb', line 16

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

  options = attachment_names.extract_options!

  attachment_names.each do |attachment_name|
    COLUMNS.each_pair do |column_name, column_definition|
      column_type, default_options = column_definition
      custom_options = options.merge(options[column_name.to_sym] || {})
      column_options = (default_options || {}).merge(custom_options)
      add_column(table_name, "#{attachment_name}_#{column_name}", column_type, column_options)
    end
  end
end

#remove_crop_attachment(table_name, *attachment_names) ⇒ Object

Raises:

  • (ArgumentError)


31
32
33
34
35
36
37
38
39
# File 'lib/paper_cropper/schema.rb', line 31

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

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