remove temp_path= and temp_data= methods so they cant be assigned with multiple attributes
This commit is contained in:
Родитель
88af79006b
Коммит
cda2d14898
|
@ -167,6 +167,7 @@ module Technoweenie # :nodoc:
|
||||||
base.after_save :after_process_attachment
|
base.after_save :after_process_attachment
|
||||||
base.after_destroy :destroy_file
|
base.after_destroy :destroy_file
|
||||||
base.after_validation :process_attachment
|
base.after_validation :process_attachment
|
||||||
|
base.attr_accessible
|
||||||
if defined?(::ActiveSupport::Callbacks)
|
if defined?(::ActiveSupport::Callbacks)
|
||||||
base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
|
base.define_callbacks :after_resize, :after_attachment_saved, :before_thumbnail_saved
|
||||||
end
|
end
|
||||||
|
@ -331,9 +332,9 @@ module Technoweenie # :nodoc:
|
||||||
end
|
end
|
||||||
if file_data.is_a?(StringIO)
|
if file_data.is_a?(StringIO)
|
||||||
file_data.rewind
|
file_data.rewind
|
||||||
self.temp_data = file_data.read
|
set_temp_data file_data.read
|
||||||
else
|
else
|
||||||
self.temp_path = file_data
|
self.temp_paths.unshift file_data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -352,22 +353,14 @@ module Technoweenie # :nodoc:
|
||||||
[] : [copy_to_temp_file(full_filename)])
|
[] : [copy_to_temp_file(full_filename)])
|
||||||
end
|
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.
|
# Gets the data from the latest temp file. This will read the file into memory.
|
||||||
def temp_data
|
def temp_data
|
||||||
save_attachment? ? File.read(temp_path) : nil
|
save_attachment? ? File.read(temp_path) : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# Writes the given data to a Tempfile and adds it to the collection of temp files.
|
# Writes the given data to a Tempfile and adds it to the collection of temp files.
|
||||||
def temp_data=(data)
|
def set_temp_data(data)
|
||||||
self.temp_path = write_to_temp_file data unless data.nil?
|
temp_paths.unshift write_to_temp_file data unless data.nil?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Copies the given file to a randomly named Tempfile.
|
# 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)
|
self.height = result.extent.size.height if respond_to?(:height)
|
||||||
|
|
||||||
# Get a new temp_path for the image before saving
|
# 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
|
result.save self.temp_path, OSX::NSJPEGFileType
|
||||||
self.size = File.size(self.temp_path)
|
self.size = File.size(self.temp_path)
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,7 +44,7 @@ module Technoweenie # :nodoc:
|
||||||
w, h = [img.width, img.height] / size.to_s
|
w, h = [img.width, img.height] / size.to_s
|
||||||
img.resize!(w, h, false)
|
img.resize!(w, h, false)
|
||||||
end
|
end
|
||||||
self.temp_path = random_tempfile_filename
|
temp_paths.unshift random_tempfile_filename
|
||||||
self.size = img.export(self.temp_path)
|
self.size = img.export(self.temp_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ module Technoweenie # :nodoc:
|
||||||
# supports.
|
# supports.
|
||||||
filename.sub! /gif$/, 'png'
|
filename.sub! /gif$/, 'png'
|
||||||
content_type.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|
|
grab_dimensions = lambda do |img|
|
||||||
self.width = img.width if respond_to?(:width)
|
self.width = img.width if respond_to?(:width)
|
||||||
self.height = img.height if respond_to?(:height)
|
self.height = img.height if respond_to?(:height)
|
||||||
|
|
|
@ -51,7 +51,7 @@ module Technoweenie # :nodoc:
|
||||||
commands.resize(size.to_s)
|
commands.resize(size.to_s)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.temp_path = img
|
temp_paths.unshift img
|
||||||
end
|
end
|
||||||
end
|
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) }
|
img.change_geometry(size.to_s) { |cols, rows, image| image.resize!(cols<1 ? 1 : cols, rows<1 ? 1 : rows) }
|
||||||
end
|
end
|
||||||
img.strip! unless attachment_options[:keep_profile]
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -52,7 +52,7 @@ class FileSystemTest < Test::Unit::TestCase
|
||||||
assert_not_created do
|
assert_not_created do
|
||||||
use_temp_file 'files/rails.png' do |file|
|
use_temp_file 'files/rails.png' do |file|
|
||||||
attachment.filename = 'rails2.png'
|
attachment.filename = 'rails2.png'
|
||||||
attachment.temp_path = File.join(fixture_path, file)
|
attachment.temp_paths.unshift File.join(fixture_path, file)
|
||||||
attachment.save!
|
attachment.save!
|
||||||
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
|
assert File.exists?(attachment.full_filename), "#{attachment.full_filename} does not exist"
|
||||||
assert !File.exists?(old_filename), "#{old_filename} still exists"
|
assert !File.exists?(old_filename), "#{old_filename} still exists"
|
||||||
|
|
|
@ -31,7 +31,7 @@ module BaseAttachmentTests
|
||||||
assert_valid attachment
|
assert_valid attachment
|
||||||
assert attachment.size > 0, "no data was set"
|
assert attachment.size > 0, "no data was set"
|
||||||
|
|
||||||
attachment.temp_data = 'wtf'
|
attachment.set_temp_data 'wtf'
|
||||||
assert attachment.save_attachment?
|
assert attachment.save_attachment?
|
||||||
attachment.save!
|
attachment.save!
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ module BaseAttachmentTests
|
||||||
assert_valid attachment
|
assert_valid attachment
|
||||||
assert attachment.size > 0, "no data was set"
|
assert attachment.size > 0, "no data was set"
|
||||||
|
|
||||||
attachment.temp_data = nil
|
attachment.set_temp_data nil
|
||||||
assert !attachment.save_attachment?
|
assert !attachment.save_attachment?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -55,7 +55,7 @@ module BaseAttachmentTests
|
||||||
assert_not_created do # no new db_file records
|
assert_not_created do # no new db_file records
|
||||||
use_temp_file 'files/rails.png' do |file|
|
use_temp_file 'files/rails.png' do |file|
|
||||||
attachment.filename = 'rails2.png'
|
attachment.filename = 'rails2.png'
|
||||||
attachment.temp_path = File.join(fixture_path, file)
|
attachment.temp_paths.unshift File.join(fixture_path, file)
|
||||||
attachment.save!
|
attachment.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -181,7 +181,7 @@ class RmagickTest < Test::Unit::TestCase
|
||||||
assert_not_created do
|
assert_not_created do
|
||||||
use_temp_file "files/rails.png" do |file|
|
use_temp_file "files/rails.png" do |file|
|
||||||
attachment.filename = 'rails2.png'
|
attachment.filename = 'rails2.png'
|
||||||
attachment.temp_path = File.join(fixture_path, file)
|
attachment.temp_paths.unshift File.join(fixture_path, file)
|
||||||
attachment.save
|
attachment.save
|
||||||
new_filenames = [attachment.reload.full_filename] + attachment.thumbnails.collect { |t| t.reload.full_filename }
|
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" }
|
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
|
# #temp_path calls #full_filename, which is not getting mixed into the attachment. Maybe we don't need to
|
||||||
# set temp_path at all?
|
# set temp_path at all?
|
||||||
#
|
#
|
||||||
# attachment.temp_path = File.join(fixture_path, file)
|
# attachment.temp_paths.unshift File.join(fixture_path, file)
|
||||||
attachment.save!
|
attachment.save!
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Загрузка…
Ссылка в новой задаче