Class: Textus::Hooks::Loader
- Inherits:
-
Object
- Object
- Textus::Hooks::Loader
- Defined in:
- lib/textus/hooks/loader.rb
Instance Method Summary collapse
-
#initialize(registry:) ⇒ Loader
constructor
A new instance of Loader.
- #load_dir(dir) ⇒ Object
Constructor Details
#initialize(registry:) ⇒ Loader
Returns a new instance of Loader.
4 5 6 |
# File 'lib/textus/hooks/loader.rb', line 4 def initialize(registry:) @registry = registry end |
Instance Method Details
#load_dir(dir) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/textus/hooks/loader.rb', line 8 def load_dir(dir) return unless File.directory?(dir) # Discard any leftover blocks from a prior partial load. Textus.drain_hook_blocks Dir.glob(File.join(dir, "**/*.rb")).sort.each do |f| # rubocop:disable Lint/RedundantDirGlobSort load(f) rescue StandardError, ScriptError => e raise UsageError.new("failed loading hook #{File.basename(f)}: #{e.class}: #{e.}") end Textus.drain_hook_blocks.each do |blk| blk.call(@registry) rescue StandardError, ScriptError => e raise UsageError.new("failed registering hook: #{e.class}: #{e.}") end end |