Skip to content

Commit

Permalink
Refactor the implementation of the schema helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
dasch committed Dec 12, 2011
1 parent ffbfc24 commit e0a6732
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions lib/paperclip/schema.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
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

0 comments on commit e0a6732

Please sign in to comment.