# File lib/paperclip/url_generator.rb, line 5 def initialize(attachment, attachment_options) @attachment = attachment @attachment_options = attachment_options end
# File lib/paperclip/url_generator.rb, line 10 def for(style_name, options) escape_url_as_needed( timestamp_as_needed( @attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name), options ), options) end
This method is all over the place.
# File lib/paperclip/url_generator.rb, line 21 def default_url if @attachment_options[:default_url].respond_to?(:call) @attachment_options[:default_url].call(@attachment) elsif @attachment_options[:default_url].is_a?(Symbol) @attachment.instance.send(@attachment_options[:default_url]) else @attachment_options[:default_url] end end
# File lib/paperclip/url_generator.rb, line 60 def escape_url(url) (url.respond_to?(:escape) ? url.escape : URI.escape(url)).gsub(/(\/.+)\?(.+\.)/, '\1%3F\2') end
# File lib/paperclip/url_generator.rb, line 52 def escape_url_as_needed(url, options) if options[:escape] escape_url(url) else url end end
# File lib/paperclip/url_generator.rb, line 31 def most_appropriate_url if @attachment.original_filename.nil? default_url else @attachment_options[:url] end end
# File lib/paperclip/url_generator.rb, line 39 def timestamp_as_needed(url, options) if options[:timestamp] && timestamp_possible? delimiter_char = url.match(/\?.+=/) ? '&' : '?' "#{url}#{delimiter_char}#{@attachment.updated_at.to_s}" else url end end
# File lib/paperclip/url_generator.rb, line 48 def timestamp_possible? @attachment.respond_to?(:updated_at) && @attachment.updated_at.present? end