lib/backgrounder/orm/base.rb in carrierwave_backgrounder-0.0.8 vs lib/backgrounder/orm/base.rb in carrierwave_backgrounder-0.0.9
- old
+ new
@@ -38,15 +38,22 @@
# add_column :users, :avatar_processing, :boolean
# end
#
def process_in_background(column, worker=::CarrierWave::Workers::ProcessAsset)
send :before_save, :"set_#{column}_processing", :if => :"trigger_#{column}_background_processing?"
- send :after_save, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_processing?"
+ if self.respond_to?(:after_commit)
+ send :after_commit, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_processing?"
+ else
+ send :after_save, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_processing?"
+ end
+ send :attr_accessor, :"process_#{column}_upload"
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
- attr_accessor :process_#{column}_upload
+ mod = Module.new
+ include mod
+ mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
+
def set_#{column}_processing
self.#{column}_processing = true if respond_to?(:#{column}_processing)
end
def enqueue_#{column}_background_job
@@ -81,13 +88,19 @@
# mount_uploader :avatar, AvatarUploader
# store_in_background :avatar, CustomWorker
# end
#
def store_in_background(column, worker=::CarrierWave::Workers::StoreAsset)
- send :after_save, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_storage?"
+ if self.respond_to?(:after_commit)
+ send :after_commit, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_storage?"
+ else
+ send :after_save, :"enqueue_#{column}_background_job", :if => :"trigger_#{column}_background_storage?"
+ end
+ send :attr_accessor, :"process_#{column}_upload"
- class_eval <<-RUBY, __FILE__, __LINE__ + 1
- attr_accessor :process_#{column}_upload
+ mod = Module.new
+ include mod
+ mod.module_eval <<-RUBY, __FILE__, __LINE__ + 1
def write_#{column}_identifier
super() and return if process_#{column}_upload
self.#{column}_tmp = _mounter(:#{column}).cache_name if _mounter(:#{column}).cache_name
end