Module: DelayedPaperclip::InstanceMethods

Defined in:
lib/delayed_paperclip.rb

Instance Method Summary collapse

Instance Method Details

#enqueue_delayed_processingObject

First mark processing then enqueue



84
85
86
87
88
89
90
91
92
# File 'lib/delayed_paperclip.rb', line 84

def enqueue_delayed_processing
  mark_enqueue_delayed_processing

  (@_enqued_for_processing || []).each do |name|
    enqueue_post_processing_for(name)
  end
  @_enqued_for_processing_with_processing = []
  @_enqued_for_processing = []
end

#enqueue_post_processing_for(name) ⇒ Object



104
105
106
# File 'lib/delayed_paperclip.rb', line 104

def enqueue_post_processing_for name
  DelayedPaperclip.enqueue(self.class.name, read_attribute(:id), name.to_sym)
end

#mark_enqueue_delayed_processingObject

setting each inididual NAME_processing to true, skipping the ActiveModel dirty setter Then immediately push the state to the database



96
97
98
99
100
101
102
# File 'lib/delayed_paperclip.rb', line 96

def mark_enqueue_delayed_processing
  unless @_enqued_for_processing_with_processing.blank? # catches nil and empty arrays
    updates = @_enqued_for_processing_with_processing.collect{|n| "#{n}_processing = :true" }.join(", ")
    updates = ActiveRecord::Base.send(:sanitize_sql_array, [updates, {:true => true}])
    self.class.unscoped.where(:id => self.id).update_all(updates)
  end
end

#prepare_enqueueing_for(name) ⇒ Object



108
109
110
111
112
113
114
115
116
117
# File 'lib/delayed_paperclip.rb', line 108

def prepare_enqueueing_for name
  if self.attributes.has_key? "#{name}_processing"
    write_attribute("#{name}_processing", true)
    @_enqued_for_processing_with_processing ||= []
    @_enqued_for_processing_with_processing << name
  end

  @_enqued_for_processing ||= []
  @_enqued_for_processing << name
end