Module: HasAttachable::Processing
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/has_attachable/processing.rb
Instance Method Summary collapse
- #attachable_field ⇒ Object
- #get_changed_attachable ⇒ Object
- #get_remove_attachable ⇒ Object
- #process_attachable? ⇒ Boolean
- #processing_options ⇒ Object
- #remove_attachable? ⇒ Boolean
- #run_process_attachable ⇒ Object
- #run_remove_attachable ⇒ Object
- #track_job_id(job_id) ⇒ Object
- #untrack_job_id(context) ⇒ Object
Instance Method Details
#attachable_field ⇒ Object
36 37 38 |
# File 'lib/has_attachable/processing.rb', line 36 def attachable_field get_changed_attachable || get_remove_attachable end |
#get_changed_attachable ⇒ Object
49 50 51 52 53 54 55 |
# 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 ⇒ Object
57 58 59 60 61 62 63 |
# 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? ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/has_attachable/processing.rb', line 5 def process_attachable? field = get_changed_attachable return false if field.nil? case [field][:type] when :downloadable, :streamable then false else send("#{field}_name_changed?") and \ send("#{field}_name").present? ? true : false end end |
#processing_options ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/has_attachable/processing.rb', line 66 def { klass: self.class.name, id: id, context: get_changed_attachable || get_remove_attachable } end |
#remove_attachable? ⇒ Boolean
41 42 43 44 45 46 47 |
# 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 ⇒ Object
17 18 19 20 |
# File 'lib/has_attachable/processing.rb', line 17 def run_process_attachable job_id = HasAttachable::Worker.perform_async('process', ) track_job_id(job_id) if self.respond_to?("#{attachable_field}_job_id") end |
#run_remove_attachable ⇒ Object
22 23 24 25 26 |
# 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', ) track_job_id(job_id) if self.respond_to?("#{attachable_field}_job_id") end |
#track_job_id(job_id) ⇒ Object
28 29 30 |
# 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) ⇒ Object
32 33 34 |
# File 'lib/has_attachable/processing.rb', line 32 def untrack_job_id(context) self.update_column "#{context}_job_id", nil end |