Module: DelayedPaperclip::ClassMethods

Defined in:
lib/delayed_paperclip.rb

Instance Method Summary collapse

Instance Method Details

#paperclip_definitionsObject



67
68
69
70
71
72
73
# File 'lib/delayed_paperclip.rb', line 67

def paperclip_definitions
  @paperclip_definitions ||= if respond_to? :attachment_definitions
    attachment_definitions
  else
    Paperclip::Tasks::Attachments.definitions_for(self)
  end
end

#process_in_background(name, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/delayed_paperclip.rb', line 42

def process_in_background(name, options = {})
  # initialize as hash
  paperclip_definitions[name][:delayed] = {}

  # Set Defaults
  only_process_default = paperclip_definitions[name][:only_process]
  only_process_default ||= []
  {
    :priority => 0,
    :only_process => only_process_default,
    :url_with_processing => DelayedPaperclip.options[:url_with_processing],
    :processing_image_url => DelayedPaperclip.options[:processing_image_url],
    :queue => DelayedPaperclip.options[:queue]
  }.each do |option, default|
    paperclip_definitions[name][:delayed][option] = options.key?(option) ? options[option] : default
  end

  # Sets callback
  if respond_to?(:after_commit)
    after_commit  :enqueue_delayed_processing
  else
    after_save    :enqueue_delayed_processing
  end
end