Class: PopulateMe::FileSystemAttachment
- Inherits:
-
Attachment
- Object
- Attachment
- PopulateMe::FileSystemAttachment
- Defined in:
- lib/populate_me/file_system_attachment.rb
Instance Attribute Summary
Attributes inherited from Attachment
Instance Method Summary collapse
Methods inherited from Attachment
#attachee_prefix, #create, #create_variations, #deletable?, #delete, #delete_all, #ensure_local_path, #field_filename, #field_options, #field_value, inherited, #initialize, #location, #location_for_filename, #location_root, middleware, middleware_options, #perform_delete, set, #settings, #url, #variations
Constructor Details
This class inherits a constructor from PopulateMe::Attachment
Instance Method Details
#next_available_filename(filename) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/populate_me/file_system_attachment.rb', line 9 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 |
#perform_create(hash) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/populate_me/file_system_attachment.rb', line 28 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 |