class Paperclip::UrlGenerator
Attributes
attachment[R]
Public Class Methods
encoder()
click to toggle source
# File lib/paperclip/url_generator.rb, line 7 def encoder @encoder ||= URI::RFC2396_Parser.new end
new(attachment)
click to toggle source
# File lib/paperclip/url_generator.rb, line 13 def initialize(attachment) @attachment = attachment end
Public Instance Methods
for(style_name, options)
click to toggle source
# File lib/paperclip/url_generator.rb, line 17 def for(style_name, options) interpolated = attachment_options[:interpolator].interpolate( most_appropriate_url, @attachment, style_name ) escaped = escape_url_as_needed(interpolated, options) timestamp_as_needed(escaped, options) end
Private Instance Methods
default_url()
click to toggle source
This method is all over the place.
# File lib/paperclip/url_generator.rb, line 32 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
escape_regex()
click to toggle source
# File lib/paperclip/url_generator.rb, line 79 def escape_regex /[\?\(\)\[\]\+]/ end
escape_url(url)
click to toggle source
# File lib/paperclip/url_generator.rb, line 71 def escape_url(url) if url.respond_to?(:escape) url.escape else self.class.escape(url).gsub(escape_regex) { |m| "%#{m.ord.to_s(16).upcase}" } end end
escape_url_as_needed(url, options)
click to toggle source
# File lib/paperclip/url_generator.rb, line 63 def escape_url_as_needed(url, options) if options[:escape] escape_url(url) else url end end
most_appropriate_url()
click to toggle source
# File lib/paperclip/url_generator.rb, line 42 def most_appropriate_url if @attachment.original_filename.nil? default_url else attachment_options[:url] end end
timestamp_as_needed(url, options)
click to toggle source
# File lib/paperclip/url_generator.rb, line 50 def timestamp_as_needed(url, options) if options[:timestamp] && timestamp_possible? delimiter_char = url.match(/\?.+=/) ? "&" : "?" "#{url}#{delimiter_char}#{@attachment.updated_at}" else url end end
timestamp_possible?()
click to toggle source
# File lib/paperclip/url_generator.rb, line 59 def timestamp_possible? @attachment.respond_to?(:updated_at) && @attachment.updated_at.present? end