module PaperclipLambda::InstanceMethods

Public Instance Methods

enqueue_delete_processing_for(name_and_path) click to toggle source
# File lib/paperclip_lambda.rb, line 77
def enqueue_delete_processing_for(name_and_path)
  name, old_path = name_and_path
  return if persisted?
  PaperclipLambda::LambdaJob.perform_later(self.class.name, id, name.to_s, { bucket: send(name).options[:bucket], old_path: old_path })
end
enqueue_lambda_processing() click to toggle source
# File lib/paperclip_lambda.rb, line 39
def enqueue_lambda_processing
  mark_enqueue_lambda_processing

  (@_attachment_for_lambda_processing || []).each do |name|
    enqueue_post_processing_for(name)
  end

  (@_attachment_for_lambda_deleting || []).each do |name_and_path|
    unless name_and_path.blank?
      enqueue_delete_processing_for(name_and_path)
    end
  end

  @_attachment_for_lambda_processing = []
  @_attachment_for_lambda_deleting = []
end
enqueue_post_processing_for(name) click to toggle source
# File lib/paperclip_lambda.rb, line 64
def enqueue_post_processing_for(name)
  attachment_changed = previous_changes[name.to_s + "_updated_at"]
  file_array = previous_changes[name.to_s + "_file_name"]

  if attachment_changed && attachment_changed.first.present? && (file_array.uniq.length == file_array.length)
    old_path = send(name).path.split('/')
    old_path = old_path.tap(&:pop).concat([file_array.first]).join('/')
    PaperclipLambda::LambdaJob.perform_later(self.class.name, id, name.to_s, { old_path: old_path })
  else
    PaperclipLambda::LambdaJob.perform_later(self.class.name, id, name.to_s)
  end
end
mark_enqueue_lambda_processing() click to toggle source
# File lib/paperclip_lambda.rb, line 56
def mark_enqueue_lambda_processing
  unless @_attachment_for_lambda_processing.blank? # catches nil and empty arrays
    updates = @_attachment_for_lambda_processing.collect{|n| "#{n}_processing = :true" }.join(", ")
    updates = ActiveRecord::Base.send(:sanitize_sql_array, [updates, {:true => true}])
    self.class.where(:id => id).update_all(updates)
  end
end
prepare_enqueueing_for(name) click to toggle source
# File lib/paperclip_lambda.rb, line 83
def prepare_enqueueing_for(name)
  @_attachment_for_lambda_processing ||= []
  @_attachment_for_lambda_processing << name
end
prepare_enqueueing_for_deletion(name) click to toggle source
# File lib/paperclip_lambda.rb, line 88
def prepare_enqueueing_for_deletion(name)
  @_attachment_for_lambda_deleting ||= []
  @_attachment_for_lambda_deleting << [name, send(name).path]
end