module Cardio::Utils
Utilities that may need to be run even when mods are not loaded.
Public Class Methods
delete_tmp_files!(id=nil)
click to toggle source
deletes tmp directory within files directory It’s here because it gets called as part of cache clearing, which sometimes gets called in a context where card mods are not loaded. Why does cache clearing need to do this??
# File lib/cardio/utils.rb, line 23 def delete_tmp_files! id=nil raise "no files directory" unless files_dir delete_tmp_files id rescue StandardError Rails.logger.info "failed to remove tmp files" end
empty_trash()
click to toggle source
# File lib/cardio/utils.rb, line 5 def empty_trash delete_trashed_files Card.where(trash: true).in_batches.update_all(left_id: nil, right_id: nil) Card.where(trash: true).in_batches.delete_all Card::Action.delete_cardless Card::Change.delete_actionless Card::Act.delete_actionless Card::Reference.clean end
seed_test_db()
click to toggle source
# File lib/cardio/utils.rb, line 15 def seed_test_db system "env RAILS_ENV=test bundle exec rake db:seed:replant" end
Private Class Methods
all_file_ids()
click to toggle source
# File lib/cardio/utils.rb, line 59 def all_file_ids dir = Card.paths["files"].existent.first Dir.entries(dir)[2..-1].map(&:to_i) end
all_trashed_card_ids()
click to toggle source
# File lib/cardio/utils.rb, line 64 def all_trashed_card_ids trashed_card_sql = %( select id from cards where trash is true ) sql_results = Card.connection.select_all(trashed_card_sql) sql_results.map(&:values).flatten.map(&:to_i) end
delete_files_with_id(dir, file_id)
click to toggle source
# File lib/cardio/utils.rb, line 44 def delete_files_with_id dir, file_id raise Card::Error, t(:core_exception_almost_deleted) if Card.exist?(file_id) ::FileUtils.rm_rf "#{dir}/#{file_id}", secure: true end
delete_tmp_files(id=nil)
click to toggle source
# File lib/cardio/utils.rb, line 50 def delete_tmp_files id=nil dir = [files_dir, "tmp", id.to_s].compact.join "/" FileUtils.rm_rf dir, secure: true end
delete_trashed_files()
click to toggle source
deletes any file not associated with a real card.
# File lib/cardio/utils.rb, line 34 def delete_trashed_files dir = Cardio.paths["files"].existent.first # TODO: handle cloud files return unless dir (all_trashed_card_ids & all_file_ids).each do |file_id| delete_files_with_id dir, file_id end end
files_dir()
click to toggle source
# File lib/cardio/utils.rb, line 55 def files_dir @files_dir ||= Cardio.paths["files"].existent.first end