module AttachmentSaver::DataStores::InColumn
Public Class Methods
included(base)
click to toggle source
# File lib/datastores/in_column.rb, line 8 def self.included(base) base.attachment_options[:column_name] ||= 'data' base.attachment_options[:temp_directory] ||= Dir.tmpdir end
Public Instance Methods
delete_attachment()
click to toggle source
# File lib/datastores/in_column.rb, line 24 def delete_attachment; end
in_storage?()
click to toggle source
# File lib/datastores/in_column.rb, line 26 def in_storage? !send(self.class.attachment_options[:column_name]).nil? end
reprocess!()
click to toggle source
there is no public_path, since you need to make a controller to pull the blob from the database
# File lib/datastores/in_column.rb, line 32 def reprocess! raise "this attachment already has a file open to process" unless uploaded_file.nil? save_temporary_and_process_attachment save! end
save_attachment()
click to toggle source
# File lib/datastores/in_column.rb, line 13 def save_attachment return unless @save_upload # this method is called every time the model is saved, not just when a new file has been uploaded send("#{self.class.attachment_options[:column_name]}=", uploaded_data) save_temporary_and_process_attachment if process_attachment? @save_upload = nil end
save_temporary_and_process_attachment()
click to toggle source
# File lib/datastores/in_column.rb, line 38 def save_temporary_and_process_attachment FileUtils.mkdir_p(self.class.attachment_options[:temp_directory]) Tempfile.open("asctemp", self.class.attachment_options[:temp_directory]) do |temp| temp.binmode temp.write(send(self.class.attachment_options[:column_name])) temp.flush process_attachment_with_wrapping(temp.path) end end
tidy_attachment()
click to toggle source
# File lib/datastores/in_column.rb, line 23 def tidy_attachment; end