Method: MassRecord::Actions#queue_for_quick_query
- Defined in:
- lib/mass_record.rb
#queue_for_quick_query(object_array, operation: :save, folder: {queued:path[:queued_queries]}, file_tag: Time.now.strftime("%Y%m%d%H%M%S%L").to_s, key: { table: "table", operation: "operation", object: "object" }, only: []) ⇒ Object
TODO: add logic to append the data if the filename already exists accepts an array of objects with the option to specify what rails operation to perform
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/mass_record.rb', line 87 def queue_for_quick_query object_array, operation: :save, folder:{queued:path[:queued_queries]}, file_tag:Time.now.strftime("%Y%m%d%H%M%S%L").to_s, key:{ table: "table", operation: "operation", object: "object" },only:[] object_array = [object_array] unless object_array.is_a? Array return false if object_array.blank? class_array = object_array.collect{|x| x.class.name} object_array = slim_data(object_array, keep:only, operation:operation) if operation.to_s == 'update' or !only.blank? or object_array.any?{|x| !x.new_record?} queue = [] object_array.each_with_index do |object,i| queue << { key[:table] => class_array[i], key[:operation] => (operation.to_s.downcase == 'save') ? specify_save(on:object) : operation , key[:object] => object } unless object.blank? end # begin File.open(folder[:queued]+"/#{operation.to_s}_#{file_tag}.json",'w'){|f| f.write queue.to_json} unless queue.blank? # rescue Exception => e # pp "#{e.message}\n#{e.backtrace[0..5].pretty_inspect}".red # end end |