Sha256: e0505c3b417d2be5b7fb385a04e5ce708793f0248fdee798627feda6cd545853

Contents?: true

Size: 1.53 KB

Versions: 3

Compression:

Stored size: 1.53 KB

Contents

require 'uri'
require 'paperclip/url_generator'

module DelayedPaperclip
  class UrlGenerator < ::Paperclip::UrlGenerator
    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? ||
            !@attachment.processing?
            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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
delayed_paperclip-3.0.0 lib/delayed_paperclip/url_generator.rb
delayed_paperclip-2.10.0 lib/delayed_paperclip/url_generator.rb
delayed_paperclip-2.9.2 lib/delayed_paperclip/url_generator.rb