Class: Textus::Hooks::Loader

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/hooks/loader.rb

Instance Method Summary collapse

Constructor Details

#initialize(bus:) ⇒ Loader

Returns a new instance of Loader.



4
5
6
# File 'lib/textus/hooks/loader.rb', line 4

def initialize(bus:)
  @bus = bus
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.message}")
  end

  Textus.drain_hook_blocks.each do |blk|
    blk.call(@bus)
  rescue StandardError, ScriptError => e
    raise UsageError.new("failed registering hook: #{e.class}: #{e.message}")
  end
end