Commit e0a67324 by Daniel Schierbeck

Refactor the implementation of the schema helpers

parent ffbfc24e
module Paperclip
module Schema
def has_attached_file(name)
column :"#{name}_file_name", :string
column :"#{name}_content_type", :string
column :"#{name}_file_size", :integer
column :"#{name}_updated_at", :datetime
@@columns = {:file_name => :string,
:content_type => :string,
:file_size => :integer,
:updated_at => :datetime}
def has_attached_file(attachment_name)
@@columns.each do |name, type|
column_name = full_column_name(attachment_name, name)
column(column_name, type)
end
end
def drop_attached_file(table_name, attachment_name)
@@columns.each do |name, type|
column_name = full_column_name(attachment_name, name)
remove_column(table_name, column_name)
end
end
def drop_attached_file(table_name, name)
remove_column table_name, :"#{name}_file_name"
remove_column table_name, :"#{name}_content_type"
remove_column table_name, :"#{name}_file_size"
remove_column table_name, :"#{name}_updated_at"
protected
def full_column_name(attachment_name, column_name)
"#{attachment_name}_#{column_name}".to_sym
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment