lib/cardio/utils.rb in card-1.102.0 vs lib/cardio/utils.rb in card-1.103.0

- old
+ new

@@ -1,39 +1,33 @@ module Cardio # Utilities that may need to be run even when mods are not loaded. module Utils - def t key, **options - ::I18n.t key, **options - end + class << self + def seed_test_db + system "env RAILS_ENV=test bundle exec rake db:fixtures:load" + end - def seed_test_db - system "env RAILS_ENV=test bundle exec rake db:fixtures:load" - end + # 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?? + def delete_tmp_files! id=nil + raise "no files directory" unless files_dir - def database_name - @database_name ||= config.database_configuration.dig Rails.env, "database" - end + delete_tmp_files id + rescue StandardError + Rails.logger.info "failed to remove tmp files" + end - # 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?? - def delete_tmp_files! id=nil - raise "no files directory" unless files_dir + private - delete_tmp_files id - rescue StandardError - Rails.logger.info "failed to remove tmp files" - end + def delete_tmp_files id=nil + dir = [files_dir, "tmp", id.to_s].compact.join "/" + FileUtils.rm_rf dir, secure: true + end - private - - def delete_tmp_files id=nil - dir = [files_dir, "tmp", id.to_s].compact.join "/" - FileUtils.rm_rf dir, secure: true - end - - def files_dir - @files_dir ||= Cardio.paths["files"].existent.first + def files_dir + @files_dir ||= Cardio.paths["files"].existent.first + end end end end