Module: PaperclipLambda::InstanceMethods

Defined in:
lib/paperclip_lambda.rb

Instance Method Summary collapse

Instance Method Details

#enqueue_delete_processing_for(name_and_path) ⇒ Object



77
78
79
80
81
# 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_processingObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# 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) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
# 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_processingObject



56
57
58
59
60
61
62
# 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) ⇒ Object



83
84
85
86
# 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) ⇒ Object



88
89
90
91
# 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