remove temp_path= and temp_data= methods so they cant be assigned with multiple attributes

This commit is contained in:
rick 2008-10-06 14:42:58 -07:00
Родитель 88af79006b
Коммит cda2d14898
9 изменённых файлов: 16 добавлений и 23 удалений

Просмотреть файл

@ -167,6 +167,7 @@ module Technoweenie # :nodoc:
base.after_save :after_process_attachment
base.after_destroy :destroy_file
base.after_validation :process_attachment
base.attr_accessible
if defined?(::ActiveSupport::Callbacks)
base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
end
@ -331,9 +332,9 @@ module Technoweenie # :nodoc:
end
if file_data.is_a?(StringIO)
file_data.rewind
self.temp_data = file_data.read
set_temp_data file_data.read
else
self.temp_path = file_data
self.temp_paths.unshift file_data
end
end
@ -352,22 +353,14 @@ module Technoweenie # :nodoc:
[] : [copy_to_temp_file(full_filename)])
end
# Adds a new temp_path to the array. This should take a string or a Tempfile. This class makes no
# attempt to remove the files, so Tempfiles should be used. Tempfiles remove themselves when they go out of scope.
# You can also use string paths for temporary files, such as those used for uploaded files in a web server.
def temp_path=(value)
temp_paths.unshift value
temp_path
end
# Gets the data from the latest temp file. This will read the file into memory.
def temp_data
save_attachment? ? File.read(temp_path) : nil
end
# Writes the given data to a Tempfile and adds it to the collection of temp files.
def temp_data=(data)
self.temp_path = write_to_temp_file data unless data.nil?
def set_temp_data(data)
temp_paths.unshift write_to_temp_file data unless data.nil?
end
# Copies the given file to a randomly named Tempfile.

Просмотреть файл

@ -46,7 +46,7 @@ module Technoweenie # :nodoc:
self.height = result.extent.size.height if respond_to?(:height)
# Get a new temp_path for the image before saving
self.temp_path = Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
temp_paths.unshift Tempfile.new(random_tempfile_filename, Technoweenie::AttachmentFu.tempfile_path).path
result.save self.temp_path, OSX::NSJPEGFileType
self.size = File.size(self.temp_path)
end

Просмотреть файл

@ -44,7 +44,7 @@ module Technoweenie # :nodoc:
w, h = [img.width, img.height] / size.to_s
img.resize!(w, h, false)
end
self.temp_path = random_tempfile_filename
temp_paths.unshift random_tempfile_filename
self.size = img.export(self.temp_path)
end

Просмотреть файл

@ -34,7 +34,7 @@ module Technoweenie # :nodoc:
# supports.
filename.sub! /gif$/, 'png'
content_type.sub!(/gif$/, 'png')
self.temp_path = write_to_temp_file(filename)
temp_paths.unshift write_to_temp_file(filename)
grab_dimensions = lambda do |img|
self.width = img.width if respond_to?(:width)
self.height = img.height if respond_to?(:height)

Просмотреть файл

@ -51,7 +51,7 @@ module Technoweenie # :nodoc:
commands.resize(size.to_s)
end
end
self.temp_path = img
temp_paths.unshift img
end
end
end

Просмотреть файл

@ -46,7 +46,7 @@ module Technoweenie # :nodoc:
img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
end
img.strip! unless attachment_options[:keep_profile]
self.temp_path = write_to_temp_file(img.to_blob)
temp_paths.unshift write_to_temp_file(img.to_blob)
end
end
end

Просмотреть файл

@ -52,7 +52,7 @@ class FileSystemTest < Test::Unit::TestCase
assert_not_created do
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
attachment.temp_path = File.join(fixture_path, file)
attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
assert !File.exists?(old_filename), "#{old_filename} still exists"

Просмотреть файл

@ -31,7 +31,7 @@ module BaseAttachmentTests
assert_valid attachment
assert attachment.size > 0, "no data was set"
attachment.temp_data = 'wtf'
attachment.set_temp_data 'wtf'
assert attachment.save_attachment?
attachment.save!
@ -45,7 +45,7 @@ module BaseAttachmentTests
assert_valid attachment
assert attachment.size > 0, "no data was set"
attachment.temp_data = nil
attachment.set_temp_data nil
assert !attachment.save_attachment?
end
end
@ -55,7 +55,7 @@ module BaseAttachmentTests
assert_not_created do # no new db_file records
use_temp_file 'files/rails.png' do |file|
attachment.filename = 'rails2.png'
attachment.temp_path = File.join(fixture_path, file)
attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
end
end

Просмотреть файл

@ -181,7 +181,7 @@ class RmagickTest < Test::Unit::TestCase
assert_not_created do
use_temp_file "files/rails.png" do |file|
attachment.filename = 'rails2.png'
attachment.temp_path = File.join(fixture_path, file)
attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save
new_filenames = [attachment.reload.full_filename] + attachment.thumbnails.collect { |t| t.reload.full_filename }
new_filenames.each { |f| assert File.exists?(f), "#{f} does not exist" }
@ -224,7 +224,7 @@ class RmagickTest < Test::Unit::TestCase
# #temp_path calls #full_filename, which is not getting mixed into the attachment. Maybe we don't need to
# set temp_path at all?
#
# attachment.temp_path = File.join(fixture_path, file)
# attachment.temp_paths.unshift File.join(fixture_path, file)
attachment.save!
end
end