Module: Abqari::PluginLoader
- Defined in:
- lib/abqari/hooks.rb
Overview
Plugin auto-loader. Walks <site_root>/plugins/**/*.rb once at
Site construction time and Kernel#loads each file in sorted
order. Plugins are conventionally tiny Ruby files that call
Abqari::Hooks.register to wire themselves into the lifecycle.
Why load instead of require: require caches by path, so a
plugin edit isn't reloaded on subsequent Site.new calls. load
re-executes every time — important for the dev-server case where
editing a plugin file should re-register its hooks on the next
incremental rebuild.
The hook table is NOT cleared between reloads. A plugin that
registers in its top-level body will accumulate duplicate
callbacks across rebuilds. Plugins that need rebuild-safe
registration should use the setup convention (see
docs/plugins.md): wrap registration in a module method called by
Abqari::Hooks.clear!-aware sites.
Constant Summary collapse
- PLUGIN_GLOB =
File.join('plugins', '**', '*.rb')
Class Method Summary collapse
Class Method Details
.load_from(site_root) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/abqari/hooks.rb', line 121 def load_from(site_root) pattern = File.join(site_root, PLUGIN_GLOB) paths = Dir.glob(pattern).sort return if paths.empty? Log.info "Loading #{paths.size} plugin file(s) from #{File.join(site_root, 'plugins')}/" paths.each do |path| load(path) rescue StandardError, ScriptError => e Log.error "plugin load failed: #{path} — #{e.class}: #{e.}" e.backtrace&.first(5)&.each { |line| Log.error " #{line}" } raise end end |