Class: Textus::Doctor::Check::Hooks

Inherits:
Textus::Doctor::Check show all
Defined in:
lib/textus/doctor/check/hooks.rb

Instance Method Summary collapse

Methods inherited from Textus::Doctor::Check

#initialize, name_key

Constructor Details

This class inherits a constructor from Textus::Doctor::Check

Instance Method Details

#callObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/textus/doctor/check/hooks.rb', line 5

def call
  out = []
  dir = File.join(store.root, "hooks")
  return out unless File.directory?(dir)

  Dir.glob(File.join(dir, "*.rb")).sort.each do |f| # rubocop:disable Lint/RedundantDirGlobSort
    registry = Textus::Hooks::Registry.new
    Textus.with_registry(registry) do
      load(f)
    end
  rescue StandardError, ScriptError => e
    out << {
      "code" => "hook.load_failed",
      "level" => "error",
      "subject" => File.basename(f),
      "message" => "#{e.class}: #{e.message}",
      "fix" => "open #{f} and fix the syntax/load error",
    }
  end
  out
end