Active Support Reloader¶ ↑
这个类定义了几个回调
to_prepare -- Run once at application startup, and also from +to_run+. to_run -- Run before a work run that is reloading. If +reload_classes_only_on_change+ is true (the default), the class unload will have already occurred. to_complete -- Run after a work run that has reloaded. If +reload_classes_only_on_change+ is false, the class unload will have occurred after the work run, but before this callback. before_class_unload -- Run immediately before the classes are unloaded. after_class_unload -- Run immediately after the classes are unloaded.
方法
- A
- B
- N
- R
- T
- W
类公共方法
after_class_unload(*args, &block) 链接
注册一个会在类卸载后立即运行的回调。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 44 def self.after_class_unload(*args, &block) set_callback(:class_unload, :after, *args, &block) end
before_class_unload(*args, &block) 链接
注册一个会在类卸载前立即运行的回调。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 39 def self.before_class_unload(*args, &block) set_callback(:class_unload, *args, &block) end
new() 链接
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 99 def initialize super @locked = false end
reload!() 链接
手动触发重载
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 51 def self.reload! executor.wrap do new.tap do |instance| instance.run! ensure instance.complete! end end prepare! end
to_prepare(*args, &block) 链接
注册一个在应用程序启动时运行一次,并且在每次代码重新加载时都会运行的回调。
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 34 def self.to_prepare(*args, &block) set_callback(:prepare, *args, &block) end
wrap(**kwargs) 链接
将提供的块作为工作单元运行,按需重新加载代码
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 71 def self.wrap(**kwargs) return yield if active? executor.wrap(**kwargs) do instance = run! begin yield ensure instance.complete! end end end
实例公共方法
release_unload_lock!() 链接
如果之前已获取卸载锁,则释放它
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 114 def release_unload_lock! if @locked @locked = false ActiveSupport::Dependencies.interlock.done_unloading end end
require_unload_lock!() 链接
获取 ActiveSupport::Dependencies::Interlock 卸载锁,确保它会自动释放
来源: 显示 | 在 GitHub 上
# File activesupport/lib/active_support/reloader.rb, line 106 def require_unload_lock! unless @locked ActiveSupport::Dependencies.interlock.start_unloading @locked = true end end