Class: SolidQueueTui::DevReloader
- Inherits:
-
Object
- Object
- SolidQueueTui::DevReloader
- Defined in:
- lib/solid_queue_tui/dev_reloader.rb
Overview
Watches source files for changes and hot-reloads them using Kernel#load. Only active when initialized — zero overhead in production.
Instance Method Summary collapse
-
#check! ⇒ Object
Returns true if any files changed and were reloaded.
-
#initialize(watch_dir) ⇒ DevReloader
constructor
A new instance of DevReloader.
Constructor Details
#initialize(watch_dir) ⇒ DevReloader
Returns a new instance of DevReloader.
7 8 9 10 11 |
# File 'lib/solid_queue_tui/dev_reloader.rb', line 7 def initialize(watch_dir) @watch_dir = watch_dir @file_mtimes = {} snapshot_all! end |
Instance Method Details
#check! ⇒ Object
Returns true if any files changed and were reloaded.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/solid_queue_tui/dev_reloader.rb', line 14 def check! changed = false ruby_files.each do |path| mtime = File.mtime(path) if @file_mtimes[path] != mtime @file_mtimes[path] = mtime begin suppress_warnings { load(path) } changed = true rescue SyntaxError, StandardError => e # Don't crash the TUI on a syntax error mid-edit. # The old code stays loaded — user just fixes and saves again. $stderr.puts "[reload] Error loading #{File.basename(path)}: #{e.}" if ENV["DEBUG"] end end end changed end |