lib/attached/attachment.rb in attached-0.2.7 vs lib/attached/attachment.rb in attached-0.2.8

- old
+ new

@@ -38,11 +38,11 @@ def self.options @options ||= { :path => ":name/:style/:identifier:extension", :default => :original, - :medium => :aws, + :medium => :local, :credentials => {}, :styles => {}, :processors => [], :aliases => [], } @@ -116,10 +116,15 @@ # Usage: # # @object.avatar.assign(...) def assign(file, identifier = "#{Guid.new}") + + if file.is_a?(Attached::Attachment) + file = file.file + end + @file = file.respond_to?(:tempfile) ? file.tempfile : file extension ||= File.extname(file.original_filename) if file.respond_to?(:original_filename) extension ||= File.extname(file.path) if file.respond_to?(:path) @@ -128,9 +133,12 @@ instance_set :size, file.size instance_set :extension, extension instance_set :identifier, identifier process + + ensure + file.close if file.respond_to?(:close) end # Save an attachment. # \ No newline at end of file