Commit f82c0d94 by Daniel Schierbeck

Further refactor the schema implementation

parent f3eacd24
...@@ -12,21 +12,26 @@ module Paperclip ...@@ -12,21 +12,26 @@ module Paperclip
:updated_at => :datetime} :updated_at => :datetime}
def has_attached_file(attachment_name) def has_attached_file(attachment_name)
@@columns.each do |name, type| with_columns_for(attachment_name) do |column_name, column_type|
column_name = full_column_name(attachment_name, name) column(column_name, column_type)
column(column_name, type)
end end
end end
def drop_attached_file(table_name, attachment_name) def drop_attached_file(table_name, attachment_name)
@@columns.each do |name, type| with_columns_for(attachment_name) do |column_name, column_type|
column_name = full_column_name(attachment_name, name)
remove_column(table_name, column_name) remove_column(table_name, column_name)
end end
end end
protected protected
def with_columns_for(attachment_name)
@@columns.each do |suffix, column_type|
column_name = full_column_name(attachment_name, suffix)
yield column_name, column_type
end
end
def full_column_name(attachment_name, column_name) def full_column_name(attachment_name, column_name)
"#{attachment_name}_#{column_name}".to_sym "#{attachment_name}_#{column_name}".to_sym
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