Module: TestConsole::Monitor
- Included in:
- TestConsole
- Defined in:
- lib/test_console/monitor.rb
Instance Method Summary collapse
-
#auto_reload! ⇒ Object
Checks for changes to watched folders and reloads the files if necessary.
-
#stop_folders_changed? ⇒ Boolean
This monitors the stop folders for changes since the console was initialised.
-
#views_changed? ⇒ Boolean
Checks wether views have changed.
Instance Method Details
#auto_reload! ⇒ Object
Checks for changes to watched folders and reloads the files if necessary
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/test_console/monitor.rb', line 10 def auto_reload! # If nil, this means that this is the first run and nothing has changed since initialising the rails env @last_reload_time = Time.now and return if @last_reload_time.nil? TestConsole::Config.watch_paths.each do |p| watch_folder = File.join(Rails.root.to_s, p) Dir.glob(File.join('..', p, '**', '*.*rb')).each do |f| if File.mtime(f) > @last_reload_time abs_path = File.join(Dir.pwd, f) rel_path = f.gsub /#{Rails.root.to_s}/, '' rel_path = rel_path.gsub /\.\.\//, '' rel_path = rel_path.gsub /#{p}\//, '' TestConsole.out "Reloading #{rel_path}", :cyan klass = Utility.class_from_filename(rel_path) Utility.const_remove(klass) if Utility.const_defined?(klass) load abs_path end end end @last_reload_time = Time.now end |
#stop_folders_changed? ⇒ Boolean
This monitors the stop folders for changes since the console was initialised
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/test_console/monitor.rb', line 34 def stop_folders_changed? # If nil, this means that this is the first run and nothing has changed since initialising the rails env return false if @last_init_time.nil? TestConsole::Config.stop_folders.each do |p| Dir.glob(File.join('..', p, '**', '*.{rb,yml}')).each do |f| if File.mtime(f) > @last_init_time error "#{f} has been changed.\nYou will need to restart the console to reload the environment" return true end end end return false end |
#views_changed? ⇒ Boolean
Checks wether views have changed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/test_console/monitor.rb', line 52 def views_changed? # If nil, this means that this is the first run and nothing has changed since initialising the rails env @last_run_time = Time.now and return false if @last_run_time.nil? return false if @checked_views TestConsole::Config.view_folders.each do |vf| watch_folder = File.join(Rails.root.to_s, vf) Dir.glob(File.join(watch_folder, '**', '*')).each do |f| if File.mtime(f) > @last_run_time @checked_views = true return true end end end @checked_views = true return false end |