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 Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, context) ⇒ Base
Returns a new instance of Base.
13
14
15
16
|
# File 'lib/overcommit/hook/base.rb', line 13
def initialize(config, context)
@config = config.for_hook(self)
@context = context
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
9
10
11
|
# File 'lib/overcommit/hook/base.rb', line 9
def config
@config
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.
87
88
89
|
# File 'lib/overcommit/hook/base.rb', line 87
def applicable_files
@applicable_files ||= modified_files.select { |file| applicable_file?(file) }
end
|
#description ⇒ Object
43
44
45
|
# File 'lib/overcommit/hook/base.rb', line 43
def description
@config['description'] || "Running #{name}"
end
|
#enabled? ⇒ Boolean
55
56
57
|
# File 'lib/overcommit/hook/base.rb', line 55
def enabled?
@config['enabled'] != false
end
|
#executable ⇒ Object
77
78
79
|
# File 'lib/overcommit/hook/base.rb', line 77
def executable
@config['required_executable']
end
|
#install_command ⇒ Object
81
82
83
|
# File 'lib/overcommit/hook/base.rb', line 81
def install_command
@config['install_command']
end
|
#name ⇒ Object
39
40
41
|
# File 'lib/overcommit/hook/base.rb', line 39
def name
self.class.name.split('::').last
end
|
#quiet? ⇒ Boolean
51
52
53
|
# File 'lib/overcommit/hook/base.rb', line 51
def quiet?
@config['quiet']
end
|
#required? ⇒ Boolean
47
48
49
|
# File 'lib/overcommit/hook/base.rb', line 47
def required?
@config['required']
end
|
#run ⇒ Object
19
20
21
|
# File 'lib/overcommit/hook/base.rb', line 19
def run
raise NotImplementedError, 'Hook must define `run`'
end
|
#run? ⇒ Boolean
63
64
65
66
67
|
# File 'lib/overcommit/hook/base.rb', line 63
def run?
enabled? &&
(!skip? || required?) &&
!(requires_modified_files? && applicable_files.empty?)
end
|
Runs the hook and transforms the status returned based on the hook’s configuration.
Poorly named because we already have a bunch of hooks in the wild that implement ‘#run`, and we needed a wrapper step to transform the status based on any custom configuration.
29
30
31
32
33
34
35
36
37
|
# File 'lib/overcommit/hook/base.rb', line 29
def run_and_transform
if output = check_for_executable
status = :fail
else
status, output = run
end
[transform_status(status), output]
end
|
#skip? ⇒ Boolean
59
60
61
|
# File 'lib/overcommit/hook/base.rb', line 59
def skip?
@config['skip']
end
|