Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Further refactor the schema implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed Dec 12, 2011
1 parent f3eacd2 commit f82c0d9
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/paperclip/schema.rb
Expand Up @@ -12,21 +12,26 @@ module Schema
: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
Expand Down

0 comments on commit f82c0d9

Please sign in to comment.