This repository has been archived by the owner on Oct 5, 2018. It is now read-only.
forked from jstorimer/delayed_paperclip
-
Notifications
You must be signed in to change notification settings - Fork 155
/
url_generator.rb
61 lines (52 loc) · 1.67 KB
/
url_generator.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
require 'uri'
require 'paperclip/url_generator'
module DelayedPaperclip
class UrlGenerator < ::Paperclip::UrlGenerator
def initialize(attachment, _compatibility = nil)
@attachment = attachment
@attachment_options = attachment.options
end
def for(style_name, options)
most_appropriate_url = @attachment.processing_style?(style_name) ? most_appropriate_url(style_name) : most_appropriate_url()
timestamp_as_needed(
escape_url_as_needed(
@attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name),
options
),
options)
end
# This method is a mess
def most_appropriate_url(style = nil)
if @attachment.processing_style?(style)
if @attachment.original_filename.nil? || delayed_default_url?(style)
if @attachment.delayed_options.nil? ||
@attachment.processing_image_url.nil? ||
default_url
else
@attachment.processing_image_url
end
else
@attachment_options[:url]
end
else
super()
end
end
def timestamp_possible?
delayed_default_url? ? false : super
end
def delayed_default_url?(style = nil)
return false if @attachment.job_is_processing
return false if @attachment.dirty?
return false if not @attachment.delayed_options.try(:[], :url_with_processing)
return false if not processing?(style)
true
end
private
def processing?(style)
return true if @attachment.processing?
return @attachment.processing_style?(style) if style
end
end
end