Module: PaperclipLambda::Attachment::InstanceMethods

Defined in:
lib/paperclip_lambda/attachment.rb

Instance Method Summary collapse

Instance Method Details

#destroy_with_lambdaObject



46
47
48
# File 'lib/paperclip_lambda/attachment.rb', line 46

def destroy_with_lambda
  instance.prepare_enqueueing_for_deletion(name)
end

#process_update_in_lambda(options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/paperclip_lambda/attachment.rb', line 23

def process_update_in_lambda(options = {})
  lambda_definitions = instance.class.paperclip_definitions[name][:lambda]
  attributes_hash = { }

  lambda_definitions[:attributes].each do |attribute|
    attributes_hash[attribute] = instance.send(attribute)
  end

  payload = {
    path: path,
    old_path: options[:old_path],
    bucket: instance.send(name).options[:bucket],
    attributes: attributes_hash
  }

  PaperclipLambda::Client.new(lambda_definitions[:function_name], payload)

  if instance.respond_to?(:"#{name}_processing?")
    instance.send("#{name}_processing=", false)
    instance.class.where(instance.class.primary_key => instance.id).update_all({ "#{name}_processing" => false })
  end
end

#save_with_lambdaObject



13
14
15
16
17
18
19
20
21
# File 'lib/paperclip_lambda/attachment.rb', line 13

def save_with_lambda
  was_dirty = @dirty

  save_without_lambda.tap do
    if was_dirty
      instance.prepare_enqueueing_for(name)
    end
  end
end