Class: Overcommit::Hook::Base
- Inherits:
-
Object
- Object
- Overcommit::Hook::Base
show all
- Extended by:
- Forwardable
- Defined in:
- lib/overcommit/hook/base.rb
Overview
Functionality common to all hooks.
Instance Method Summary
collapse
Constructor Details
#initialize(config, context) ⇒ Base
Returns a new instance of Base.
10
11
12
13
|
# File 'lib/overcommit/hook/base.rb', line 10
def initialize(config, context)
@config = config.for_hook(self)
@context = context
end
|
Instance Method Details
#applicable_files ⇒ Object
Gets a list of staged files that apply to this hook based on its configured ‘include` and `exclude` lists.
60
61
62
|
# File 'lib/overcommit/hook/base.rb', line 60
def applicable_files
@applicable_files ||= modified_files.select { |file| applicable_file?(file) }
end
|
#description ⇒ Object
24
25
26
|
# File 'lib/overcommit/hook/base.rb', line 24
def description
@config['description'] || "Running #{name}"
end
|
#enabled? ⇒ Boolean
36
37
38
|
# File 'lib/overcommit/hook/base.rb', line 36
def enabled?
@config['enabled'] != false
end
|
#name ⇒ Object
20
21
22
|
# File 'lib/overcommit/hook/base.rb', line 20
def name
self.class.name.split('::').last
end
|
#quiet? ⇒ Boolean
32
33
34
|
# File 'lib/overcommit/hook/base.rb', line 32
def quiet?
@config['quiet']
end
|
#required? ⇒ Boolean
28
29
30
|
# File 'lib/overcommit/hook/base.rb', line 28
def required?
@config['required']
end
|
#run ⇒ Object
16
17
18
|
# File 'lib/overcommit/hook/base.rb', line 16
def run
raise NotImplementedError, 'Hook must define `run`'
end
|
#run? ⇒ Boolean
44
45
46
47
48
|
# File 'lib/overcommit/hook/base.rb', line 44
def run?
enabled? &&
(!skip? || required?) &&
!(requires_modified_files? && applicable_files.empty?)
end
|
#skip? ⇒ Boolean
40
41
42
|
# File 'lib/overcommit/hook/base.rb', line 40
def skip?
@config['skip']
end
|