module HasAttachable::Processing
Public Instance Methods
attachable_field()
click to toggle source
# File lib/has_attachable/processing.rb, line 36 def attachable_field get_changed_attachable || get_remove_attachable end
get_changed_attachable()
click to toggle source
# File lib/has_attachable/processing.rb, line 49 def get_changed_attachable changed_attachable = nil attachable_fields.each do |field| changed_attachable = field if changes.has_key?("#{field}_name") end changed_attachable end
get_remove_attachable()
click to toggle source
# File lib/has_attachable/processing.rb, line 57 def get_remove_attachable remove_attachable = nil attachable_fields.each do |field| remove_attachable = field if send("async_remove_#{field}") end remove_attachable end
process_attachable?()
click to toggle source
# File lib/has_attachable/processing.rb, line 5 def process_attachable? field = get_changed_attachable return false if field.nil? case attachable_options[field][:type] when :downloadable, :streamable then false else send("#{field}_name_changed?") and \ send("#{field}_name").present? ? true : false end end
processing_options()
click to toggle source
# File lib/has_attachable/processing.rb, line 66 def processing_options { klass: self.class.name, id: id, context: get_changed_attachable || get_remove_attachable } end
remove_attachable?()
click to toggle source
# File lib/has_attachable/processing.rb, line 41 def remove_attachable? field = get_remove_attachable return false if field.nil? send("async_remove_#{field}") and \ send("#{field}_name").present? ? true : false end
run_process_attachable()
click to toggle source
# File lib/has_attachable/processing.rb, line 17 def run_process_attachable job_id = HasAttachable::Worker.perform_async('process', processing_options) track_job_id(job_id) if self.respond_to?("#{attachable_field}_job_id") end
run_remove_attachable()
click to toggle source
# File lib/has_attachable/processing.rb, line 22 def run_remove_attachable self.update_attribute("#{get_remove_attachable}_name", nil) job_id = HasAttachable::Worker.perform_async('remove', processing_options) track_job_id(job_id) if self.respond_to?("#{attachable_field}_job_id") end
track_job_id(job_id)
click to toggle source
# File lib/has_attachable/processing.rb, line 28 def track_job_id(job_id) self.update_column "#{attachable_field}_job_id", job_id end
untrack_job_id(context)
click to toggle source
# File lib/has_attachable/processing.rb, line 32 def untrack_job_id(context) self.update_column "#{context}_job_id", nil end