Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Further refactor the schema implementation

  • Loading branch information...
commit f82c0d94f1fad37575b33ba67998ea7fa1f1fe41 1 parent f3eacd2
@dasch dasch authored
Showing with 10 additions and 5 deletions.
  1. +10 −5 lib/paperclip/schema.rb
View
15 lib/paperclip/schema.rb
@@ -12,21 +12,26 @@ module Schema
: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)
+ with_columns_for(attachment_name) do |column_name, column_type|
+ column(column_name, column_type)
end
end
def drop_attached_file(table_name, attachment_name)
- @@columns.each do |name, type|
- column_name = full_column_name(attachment_name, name)
+ with_columns_for(attachment_name) do |column_name, column_type|
remove_column(table_name, column_name)
end
end
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)
"#{attachment_name}_#{column_name}".to_sym
end
Please sign in to comment.
Something went wrong with that request. Please try again.