module SeoAttachment::InstanceMethods
Public Instance Methods
directory()
click to toggle source
# File lib/seo_attachment/seo_attachment.rb, line 27 def directory data_name = seo_attachment_options[:data_name] return if self.send(data_name).path.nil? data_files = self.send(data_name).path.split("/") data_files.delete_at(data_files.size-1) data_files.push("*.*").join('/') end
interpolates_file_names()
click to toggle source
# File lib/seo_attachment/seo_attachment.rb, line 35 def interpolates_file_names data_name = seo_attachment_options[:data_name] return if self.send("#{data_name}_file_size").blank? normally_file_name = self.send(seo_attachment_options[:normally_method].to_s) extension = File.extname(self.send("#{data_name}_file_name")).downcase rescue nil old_file = self.send("#{data_name}_file_name") new_file = "#{normally_file_name}#{extension}" self.send(data_name).instance_write(:file_name, new_file) files = Dir[directory] files.each do |file| dir_array = file.split("/") dir_array.pop dir = dir_array.join('/') prefix = file.split("/").last.split("-")[0] was = File.join(dir, "#{prefix}-#{old_file}") build = File.join(dir, "#{prefix}-#{new_file}") if File.exist?(was) && was != build FileUtils.mv was, build end end end