Sha256: 182a00e17bddabbc6731e488b50604536989785868c2497faaa01fcf4a977cd0

Contents?: true

Size: 1.88 KB

Versions: 1

Compression:

Stored size: 1.88 KB

Contents

require 'uri'

module DelayedPaperclip
  module UrlGenerator
    def self.included(base)
      base.alias_method_chain :most_appropriate_url, :processed
      base.alias_method_chain :timestamp_possible?, :processed
      base.alias_method_chain :for, :processed
    end

    def for_with_processed(style_name, options)
      most_appropriate_url = most_appropriate_url(style_name)

      escape_url_as_needed(
        timestamp_as_needed(
          @attachment_options[:interpolator].interpolate(most_appropriate_url, @attachment, style_name),
          options
      ), options)
    end

    def most_appropriate_url_with_processed(style = nil)
      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
    end

    def timestamp_possible_with_processed?
      if delayed_default_url?
        false
      else
        timestamp_possible_without_processed?
      end
    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

      # OLD CRAZY CONDITIONAL
      # TODO: Delete
      # !(
      #   @attachment.job_is_processing ||
      #   @attachment.dirty? ||
      #   !@attachment.delayed_options.try(:[], :url_with_processing) ||
      #   !(@attachment.instance.respond_to?(:"#{@attachment.name}_processing?") && @attachment.processing?)
      # )
    end

    private
    def processing?(style)
      return true if @attachment.processing?

      return @attachment.processing_style?(style) if style
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
delayed_paperclip-2.7.0 lib/delayed_paperclip/url_generator.rb