Method: Spring::Application#preload

Defined in:
lib/spring/application.rb

#preloadObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/spring/application.rb', line 36

def preload
  log "preloading app"

  require Spring.application_root_path.join("config", "application")

  # config/environments/test.rb will have config.cache_classes = true. However
  # we want it to be false so that we can reload files. This is a hack to
  # override the effect of config.cache_classes = true. We can then actually
  # set config.cache_classes = false after loading the environment.
  Rails::Application.initializer :initialize_dependency_mechanism, group: :all do
    ActiveSupport::Dependencies.mechanism = :load
  end

  # Ensure eager loading does not take place, even though it usually would do
  # in test mode with config.cache_classes = true. Eager loading in this situation
  # just makes the initial run take longer without much gain in subsequent runs,
  # at least in my testing.
  Rails::Application::Finisher.initializers.delete_if { |i| i.name == :eager_load! }

  require Spring.application_root_path.join("config", "environment")

  Rails.application.config.cache_classes = false
  disconnect_database

  watcher.add loaded_application_features
  watcher.add Spring.gemfile, "#{Spring.gemfile}.lock"
  watcher.add Rails.application.paths["config/initializers"]

  @preloaded = true
end