class Paperclip::Storage::Dropbox::PathGenerator
Public Class Methods
new(attachment, attachment_options)
click to toggle source
# File lib/paperclip/storage/dropbox/path_generator.rb, line 8 def initialize(attachment, attachment_options) @attachment = attachment @attachment_options = attachment_options end
Public Instance Methods
generate(style)
click to toggle source
# File lib/paperclip/storage/dropbox/path_generator.rb, line 13 def generate(style) path = if normal_path_style? generate_from_string(style) else generate_from_proc(style) end path end
Private Instance Methods
file_path_proc()
click to toggle source
Oh my god, this is so ugly, why did I do ever do this? Ah, well, If nothing, it demonstrates what kind of evil things you can do in Ruby :)
# File lib/paperclip/storage/dropbox/path_generator.rb, line 46 def file_path_proc return @attachment_options[:dropbox_options][:path] if @attachment_options[:dropbox_options][:path] if @attachment_options[:dropbox_options][:unique_filename] eval %(proc { |style| "\#{ActiveModel::Naming.param_key(self.class)}_\#{id}_\#{#{@attachment.name}.name}" }) else eval %(proc { |style| #{@attachment.name}.original_filename }) end end
generate_from_proc(style)
click to toggle source
# File lib/paperclip/storage/dropbox/path_generator.rb, line 32 def generate_from_proc(style) path = @attachment.instance.instance_exec(style, &file_path_proc) style_suffix = (style != @attachment.default_style ? "_#{style}" : "") extension = File.extname(@attachment.original_filename) if extension.present? and path =~ /#{extension}$/ path.sub(extension, style_suffix + extension) else path + style_suffix end end
generate_from_string(style)
click to toggle source
# File lib/paperclip/storage/dropbox/path_generator.rb, line 28 def generate_from_string(style) @attachment_options[:interpolator].interpolate(@attachment.send(:path_option), @attachment, style) end
normal_path_style?()
click to toggle source
# File lib/paperclip/storage/dropbox/path_generator.rb, line 24 def normal_path_style? @attachment_options[:path].present? end