Sha256: 8d89255f036f642392345fc696fe2b29fab5222b55449e3da62be69e80e8ae73

Contents?: true

Size: 598 Bytes

Versions: 5

Compression:

Stored size: 598 Bytes

Contents

# frozen_string_literal: true

module Paperweight
  # Removes all previous image files matching the given pattern.
  class PurgeJob < ActiveJob::Base
    PLACEHOLDER = ':style'

    queue_as :default

    def perform(pattern, styles)
      styles.each do |style|
        Storage.adapter.delete(pattern.gsub(PLACEHOLDER, style))
      end
    end

    def self.perform_later_for(model, image_uuid = nil)
      model.image_uuid = image_uuid if image_uuid

      perform_later(
        Location.new(model, PLACEHOLDER).path,
        model.class.image_styles.keys.map(&:to_s)
      )
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
paperweight-0.0.5 lib/paperweight/purge_job.rb
paperweight-0.0.4 lib/paperweight/purge_job.rb
paperweight-0.0.3 lib/paperweight/purge_job.rb
paperweight-0.0.2 lib/paperweight/purge_job.rb
paperweight-0.0.1 lib/paperweight/purge_job.rb