module LibReload
Hot-reload shared lib/ code in a running bot process (see RabbotMeta.reload_libs!). Skips boot/signal/console infrastructure that must not be redefined mid-flight.
Constants
- EXCLUDED_BASENAMES
- LIB_DIR
- PASSES
- RABBOT_DB_LOAD_ORDER
- ROOT
Public Instance Methods
Source
# File lib/lib_reload.rb, line 48 def excluded?(path) EXCLUDED_BASENAMES.include?(File.basename(path)) || path.include?("#{File::SEPARATOR}bot_console#{File::SEPARATOR}") || path.include?("#{File::SEPARATOR}vendor#{File::SEPARATOR}") end
Source
# File lib/lib_reload.rb, line 28 def lib_paths paths = Dir.glob(File.join(LIB_DIR, "**", "*.rb")) .sort .reject { |path| excluded?(path) } order_rabbot_db_files(paths) end
Source
# File lib/lib_reload.rb, line 35 def order_rabbot_db_files(paths) rabbot_db = paths.select { |path| path.include?("#{File::SEPARATOR}rabbot_db#{File::SEPARATOR}") } return paths if rabbot_db.empty? ordered = RABBOT_DB_LOAD_ORDER.filter_map do |basename| rabbot_db.find { |path| File.basename(path) == basename } end ordered += rabbot_db - ordered other = paths - rabbot_db other + ordered end
Source
# File lib/lib_reload.rb, line 87 def rel_path(path) path.sub("#{ROOT}#{File::SEPARATOR}", "") end
Source
# File lib/lib_reload.rb, line 54 def reload!(passes: PASSES) reloaded = [] errors = [] passes.times do lib_paths.each do |path| case reload_file(path) in :ok reloaded << rel_path(path) in :error, message errors << "#{rel_path(path)}: #{message}" else nil end end end { reloaded: reloaded.uniq, errors: errors.uniq } end
Source
# File lib/lib_reload.rb, line 74 def reload_file(path) return :missing unless File.file?(path) verbose = $VERBOSE $VERBOSE = nil load path :ok rescue StandardError => e [:error, e.message] ensure $VERBOSE = verbose if defined?(verbose) end