forked from sds/overcommit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.rb
More file actions
36 lines (32 loc) · 1015 Bytes
/
base.rb
File metadata and controls
36 lines (32 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
module Overcommit::HookLoader
# Responsible for loading hooks from a file.
class Base
# @param config [Overcommit::Configuration]
# @param context [Overcommit::HookContext]
# @param logger [Overcommit::Logger]
def initialize(config, context, logger)
@config = config
@context = context
@log = logger
end
# When implemented in subclasses, loads the hooks for which that subclass is
# responsible.
#
# @return [Array<Hook>]
def load_hooks
raise NotImplementedError
end
private
attr_reader :log
# Load and return a {Hook} from a CamelCase hook name.
def create_hook(hook_name)
Overcommit::Hook.const_get(@context.hook_class_name).
const_get(hook_name).
new(@config, @context)
rescue LoadError, NameError => error
raise Overcommit::Exceptions::HookLoadError,
"Unable to load hook '#{hook_name}': #{error}",
error.backtrace
end
end
end