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

Version Path
populate-me-0.23.0 lib/populate_me/file_system_attachment.rb
populate-me-0.22.1 lib/populate_me/file_system_attachment.rb
populate-me-0.22.0 lib/populate_me/file_system_attachment.rb
populate-me-0.21.0 lib/populate_me/file_system_attachment.rb
populate-me-0.20.0 lib/populate_me/file_system_attachment.rb
populate-me-0.19.0 lib/populate_me/file_system_attachment.rb
populate-me-0.18.1 lib/populate_me/file_system_attachment.rb
populate-me-0.18.0 lib/populate_me/file_system_attachment.rb
populate-me-0.17.0 lib/populate_me/file_system_attachment.rb
populate-me-0.16.0 lib/populate_me/file_system_attachment.rb
populate-me-0.15.0 lib/populate_me/file_system_attachment.rb
populate-me-0.14.0 lib/populate_me/file_system_attachment.rb
populate-me-0.13.2 lib/populate_me/file_system_attachment.rb
populate-me-0.13.1 lib/populate_me/file_system_attachment.rb
populate-me-0.13.0 lib/populate_me/file_system_attachment.rb
populate-me-0.12.0 lib/populate_me/file_system_attachment.rb
populate-me-0.11.0 lib/populate_me/file_system_attachment.rb
populate-me-0.10.1 lib/populate_me/file_system_attachment.rb
populate-me-0.10.0 lib/populate_me/file_system_attachment.rb
populate-me-0.9.2 lib/populate_me/file_system_attachment.rb