Sha256: 61c5cafb6f3a19b4848ad3d9209ea07dc5f4f4c53f0808c65ec0d8f9619c7ff4
Contents?: true
Size: 1022 Bytes
Versions: 44
Compression:
Stored size: 1022 Bytes
Contents
require 'populate_me/attachment' module PopulateMe class FileSystemAttachment < Attachment set :root, File.expand_path('public') def next_available_filename filename FileUtils.mkdir_p self.location_root ext = File.extname(filename) base = File.basename(filename,ext) i = 0 loop do suffix = i==0 ? '' : "-#{i}" potential_filename = [base,suffix,ext].join potential_location = self.location_for_filename(potential_filename) if File.exist?(potential_location) i += 1 else filename = potential_filename break end end filename end def perform_create hash return File.basename(hash[:variation_path]) unless WebUtils.blank?(hash[:variation_path]) source = hash[:tempfile].path filename = self.next_available_filename hash[:filename] destination = self.location_for_filename filename FileUtils.cp source, destination filename end end end
Version data entries
44 entries across 44 versions & 1 rubygems