class ActiveSupport::Reloader
unloaded.
after_class_unload – Run immediately after the classes are
unloaded.
before_class_unload – Run immediately before the classes are
have occurred after the work run, but before this callback.reload_classes_only_on_change
is false, the class unload will
to_complete – Run after a work run that has reloaded. If
unload will have already occurred.reload_classes_only_on_change
is true (the default), the class
to_run – Run before a work run that is reloading. Ifto_run
.
to_prepare – Run once at application startup, and also from
This class defines several callbacks:
= Active Support Reloader
def self.after_class_unload(*args, &block)
def self.after_class_unload(*args, &block) set_callback(:class_unload, :after, *args, &block) end
def self.before_class_unload(*args, &block)
def self.before_class_unload(*args, &block) set_callback(:class_unload, *args, &block) end
def self.check! # :nodoc:
def self.check! # :nodoc: @should_reload ||= check.call end
def self.prepare! # :nodoc:
def self.prepare! # :nodoc: new.run_callbacks(:prepare) end
def self.reload!
def self.reload! executor.wrap do new.tap do |instance| instance.run! ensure instance.complete! end end prepare! end
def self.reloaded! # :nodoc:
def self.reloaded! # :nodoc: @should_reload = false end
def self.run!(reset: false) # :nodoc:
def self.run!(reset: false) # :nodoc: if check! super else Null end end
def self.to_prepare(*args, &block)
def self.to_prepare(*args, &block) set_callback(:prepare, *args, &block) end
def self.wrap(**kwargs)
def self.wrap(**kwargs) return yield if active? executor.wrap(**kwargs) do instance = run! begin yield ensure instance.complete! end end end
def class_unload!(&block) # :nodoc:
def class_unload!(&block) # :nodoc: require_unload_lock! run_callbacks(:class_unload, &block) end
def complete! # :nodoc:
def complete! # :nodoc: super self.class.reloaded! ensure release_unload_lock! end
def initialize
def initialize super @locked = false end
def release_unload_lock!
def release_unload_lock! if @locked @locked = false ActiveSupport::Dependencies.interlock.done_unloading end end
def require_unload_lock!
Acquire the ActiveSupport::Dependencies::Interlock unload lock,
def require_unload_lock! unless @locked ActiveSupport::Dependencies.interlock.start_unloading @locked = true end end
def run! # :nodoc:
def run! # :nodoc: super release_unload_lock! end