Module: DelayedPaperclip::ClassMethods

Defined in:
lib/delayed_paperclip.rb

Instance Method Summary collapse

Instance Method Details

#paperclip_definitionsObject



71
72
73
74
75
76
77
# File 'lib/delayed_paperclip.rb', line 71

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

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



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/delayed_paperclip.rb', line 46

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