Class: Merb::BootLoader::ReloadClasses

Inherits:
Merb::BootLoader show all
Defined in:
lib/merb-core/bootloader.rb

Defined Under Namespace

Classes: TimedExecutor

Class Method Summary collapse

Methods inherited from Merb::BootLoader

after, after_app_loads, before, before_app_loads, default_framework, finished?, inherited, move_klass

Class Method Details

.reload(paths) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Reloads all files which have been modified since they were last loaded.

Returns

nil



1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
# File 'lib/merb-core/bootloader.rb', line 1268

def self.reload(paths)
  paths.each do |file|
    next if LoadClasses::MTIMES[file] &&
      LoadClasses::MTIMES[file] == File.mtime(file)

    LoadClasses.reload(file)
  end
  
  nil
end

.runObject

Set up the class reloader if class reloading is enabled. This checks periodically for modifications to files loaded by the LoadClasses BootLoader and reloads them when they are modified.

Returns

nil



1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
# File 'lib/merb-core/bootloader.rb', line 1238

def self.run
  return unless Merb::Config[:reload_classes]

  paths = []
  Merb.load_paths.each do |path_name, file_info|
    path, glob = file_info
    next unless glob
    paths << Dir[path / glob]
  end

  if Merb.dir_for(:application) && File.file?(Merb.dir_for(:application))
    paths << Merb.dir_for(:application)
  end

  paths.flatten!

  TimedExecutor.every(Merb::Config[:reload_time] || 0.5) do
    GC.start
    reload(paths)
  end
  
  nil
end