0
@@ -52,11 +52,33 @@ module AttachmentFu
0
# # PLUS any fields that your tasks may use.
0
def is_attachment(options = {}, &block)
0
-
include AttachmentFu::InstanceMethods0
+
setup_attachment_fu_on(self)0
self.queued_attachment = options[:queued]
0
self.attachment_path = options[:path] || attachment_path || File.join("public", table_name)
0
self.attachment_tasks(&block)
0
+ def setup_attachment_fu_on(klass)
0
+ attr_writer :attachment_tasks
0
+ def attachment_tasks(&block)
0
+ @attachment_tasks ||= superclass.respond_to?(:attachment_tasks) ? superclass.attachment_tasks.copy : AttachmentFu::Tasks.new(self)
0
+ @attachment_tasks.instance_eval(&block) if block
0
+ include AttachmentFu::InstanceMethods
0
+ attr_reader :temp_path
0
+ class_inheritable_accessor :queued_attachment
0
+ class_inheritable_accessor :attachment_path
0
+ before_create :set_new_attachment
0
+ after_save :save_attachment
0
+ after_destroy :delete_attachment
0
# joined with #attachment_path to get the full path
0
@@ -85,24 +107,6 @@ module AttachmentFu
0
# This mixin is included in attachment classes by AttachmentFu::SetupMethods.is_attachment.
0
- def self.included(base)
0
- attr_writer :attachment_tasks
0
- def attachment_tasks(&block)
0
- @attachment_tasks ||= superclass.respond_to?(:attachment_tasks) ? superclass.attachment_tasks.copy : AttachmentFu::Tasks.new(self)
0
- @attachment_tasks.instance_eval(&block) if block
0
- base.send :attr_reader, :temp_path
0
- base.send :class_inheritable_accessor, :queued_attachment
0
- base.send :class_inheritable_accessor, :attachment_path
0
- base.before_create :set_new_attachment
0
- base.after_save :save_attachment
0
- base.after_destroy :delete_attachment
0
# Strips filename of any funny characters.
0
strip_filename value if value
0
@@ -128,10 +132,11 @@ module AttachmentFu
0
self.filename = file_data.original_filename
0
if file_data.respond_to?(:rewind) # it's an IO object
0
- self.temp_path = Tempfile.new(filename)
0
- temp_path << file_data.read
0
+ tmp = Tempfile.new(filename)
0
self.temp_path = file_data
Comments
No one has commented yet.