Skip to content

Instantly share code, notes, and snippets.

@danielevans
Created May 29, 2011 07:51
Show Gist options
  • Save danielevans/997550 to your computer and use it in GitHub Desktop.
Save danielevans/997550 to your computer and use it in GitHub Desktop.
multiple dynamic file storage for paperclip
module Paperclip
class Attachment
attr_accessor :queued_for_write, :queued_for_delete
end
end
@attachment.instance.extra_files ||= []
@attachment.instance.extra_files << File.join(File.dirname(@attachment.path), "special_output_file_name")
def queue_existing_for_delete
return unless file?
@queued_for_delete = [@queued_for_delete, instance.extra_files].flatten.compact.uniq
end
serialize :extra_files
module Paperclip
class Interpolations
alias :old_extension, :extension
def extension(attachment, style_name)
if it_is_one_of_the_special_files # this test depends on the situation
ext = File.extname(style_name) # rip off the extension
ext.slice! 0
ext
else
old_extension
end
end
alias :old_style, :style
def style(attachment, style_name)
if it_is_one_of_the_special_files
File.basename(style_name, File.extname(style_name))
else
old_style
end
end
end
end
module Paperclip
class MyProcessor < Processor
def make
Paperclip.run "yourfancyprocessor", "args"
@attachment.queued_for_write["special_output_file_name"] = File.open(File.join(File.dirname(@file.path), "special_output_file_name"))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment