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, before_master_shutdown, before_worker_shutdown, default_framework, finished?, inherited, move_klass

Class Method Details

.build_pathsObject

Returns a list of the paths on the merb application stack

Returns

nil

:api: private


1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
# File 'lib/merb-core/bootloader.rb', line 1436

def self.build_paths
  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!

  return paths
end

.reload(paths = []) ⇒ Object

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

Returns

nil

:api: private


1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
# File 'lib/merb-core/bootloader.rb', line 1419

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

.reload!Object

Reloads all the files on the Merb application path

Returns

nil

:api: private


1409
1410
1411
# File 'lib/merb-core/bootloader.rb', line 1409

def self.reload!
  reload(build_paths)
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

:api: plugin


1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
# File 'lib/merb-core/bootloader.rb', line 1392

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

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

  nil
end