@@ -8,26 +8,37 @@ module Overcommit::HookContext
8
8
# This is also important to house in a separate object so that any
9
9
# calculations can be memoized across all hooks in a single object, which
10
10
# helps with performance.
11
+ #
12
+ # @abstract
11
13
class Base
14
+ # Creates a hook context from the given configuration and input options.
15
+ #
12
16
# @param config [Overcommit::Configuration]
13
17
# @param args [Array<String>]
18
+ # @param input [IO] standard input stream
14
19
def initialize ( config , args , input )
15
20
@config = config
16
21
@args = args
17
22
@input = input
18
23
end
19
24
20
25
# Returns the camel-cased type of this hook (e.g. PreCommit)
26
+ #
27
+ # @return [String]
21
28
def hook_class_name
22
29
self . class . name . split ( '::' ) . last
23
30
end
24
31
25
32
# Returns the snake-cased type of this hook (e.g. pre_commit)
33
+ #
34
+ # @return [String]
26
35
def hook_type_name
27
36
Overcommit ::Utils . snake_case ( hook_class_name )
28
37
end
29
38
30
39
# Returns the actual name of the hook script being run (e.g. pre-commit).
40
+ #
41
+ # @return [String]
31
42
def hook_script_name
32
43
hook_type_name . gsub ( '_' , '-' )
33
44
end
@@ -37,7 +48,7 @@ def hook_script_name
37
48
# This is called before the hooks are run by the [HookRunner]. Different
38
49
# hook types can perform different setup.
39
50
def setup_environment
40
- # Implemented by subclass
51
+ # Implemented by subclass, if applicable
41
52
end
42
53
43
54
# Resets the environment to an appropriate state.
@@ -46,18 +57,23 @@ def setup_environment
46
57
# Different hook types can perform different cleanup operations, which are
47
58
# intended to "undo" the results of the call to {#setup_environment}.
48
59
def cleanup_environment
49
- # Implemented by subclass
60
+ # Implemented by subclass, if applicable
50
61
end
51
62
52
63
# Returns a list of files that have been modified.
53
64
#
54
65
# By default, this returns an empty list. Subclasses should implement if
55
66
# there is a concept of files changing for the type of hook being run.
67
+ #
68
+ # @return [Array<String>]
56
69
def modified_files
57
70
[ ]
58
71
end
59
72
60
- # Returns an array of lines passed to the hook via STDIN.
73
+ # Returns an array of lines passed to the hook via the standard input
74
+ # stream.
75
+ #
76
+ # @return [Array<String>]
61
77
def input_lines
62
78
@input_lines ||= @input . read . split ( "\n " )
63
79
end
0 commit comments