Class: DelayedPaperclip::UrlGenerator

Inherits:
Paperclip::UrlGenerator
  • Object
show all
Defined in:
lib/delayed_paperclip/url_generator.rb

Instance Method Summary collapse

Constructor Details

#initialize(attachment, _compatibility = nil) ⇒ UrlGenerator

Returns a new instance of UrlGenerator.



6
7
8
9
# File 'lib/delayed_paperclip/url_generator.rb', line 6

def initialize(attachment, _compatibility = nil)
  @attachment = attachment
  @attachment_options = attachment.options
end

Instance Method Details

#delayed_default_url?(style = nil) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
49
50
51
52
# File 'lib/delayed_paperclip/url_generator.rb', line 46

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

#for(style_name, options) ⇒ Object



11
12
13
14
15
16
17
18
19
# File 'lib/delayed_paperclip/url_generator.rb', line 11

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

#most_appropriate_url(style = nil) ⇒ Object

This method is a mess



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/delayed_paperclip/url_generator.rb', line 22

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? ||
        !@attachment.processing?
        default_url
      else
        @attachment.processing_image_url
      end

    else
      @attachment_options[:url]
    end
  else
    super()
  end
end

#timestamp_possible?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/delayed_paperclip/url_generator.rb', line 42

def timestamp_possible?
  delayed_default_url? ? false : super
end