Module: PaperclipAsync

Defined in:
lib/paperclip_async.rb,
lib/paperclip_async/railtie.rb,
lib/paperclip_async/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Instance Method Details

#paperclip_async(attachment, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/paperclip_async.rb', line 5

def paperclip_async attachment, options = {}
  raise "class #{self.name} doesn't have paperclip attachment named #{attachment}" unless attachment_definitions.keys.include?(attachment.to_sym)
  instance_eval "    attr_accessor :post_process_\#{attachment}, :\#{attachment}_marked_to_process\n    \n    before_post_process do\n      self.\#{attachment}_marked_to_process= !post_process_\#{attachment}\n      post_process_\#{attachment} ? true : false \n    end\n    \n    after_commit if: ->(o){ o.\#{attachment}_marked_to_process && o.persisted? } do\n      self.class.delay(\#{options}).process_attachment(self.id, :\#{attachment})\n    end\n  CODE\n  \n  unless respond_to?(:process_attachment)\n    define_singleton_method :process_attachment do |id, attachment_name|\n      object = find(id)\n      object.send \"post_process_\#{attachment_name}=\", true\n      attachment_object = object.send(attachment_name)\n      styles = attachment_object.styles.keys\n      attachment_object.options[:only_process] = styles\n      attachment_object.assign(attachment_object)\n      unless styles.include? :original\n        file = attachment_object.queued_for_write.delete(:original) \n        if file\n          file.close unless file.closed?\n          file.unlink if file.respond_to?(:unlink) && file.path.present? && File.exist?(file.path)\n        end\n      end\n      attachment_object.save\n    end\n  end\nend\n", __FILE__, __LINE__ +1