Class: GitHooks::Section
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Array
#extract_options, #extract_options!, #maximum, #minimum, #select_with_index
Constructor Details
#initialize(name, hook, &block) ⇒ Section
Returns a new instance of Section.
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/githooks/section.rb', line 35
def initialize(name, hook, &block)
@name = name.to_s.titleize
@success = true
@actions = []
@limiters = hook.limiters
@hook = hook
@benchmark = 0
instance_eval(&block)
waiting!
end
|
Instance Attribute Details
#benchmark ⇒ Object
Returns the value of attribute benchmark.
24
25
26
|
# File 'lib/githooks/section.rb', line 24
def benchmark
@benchmark
end
|
Returns the value of attribute hook.
24
25
26
|
# File 'lib/githooks/section.rb', line 24
def hook
@hook
end
|
Returns the value of attribute limiters.
24
25
26
|
# File 'lib/githooks/section.rb', line 24
def limiters
@limiters
end
|
#name(phase = GitHooks::HOOK_NAME) ⇒ Object
Returns the value of attribute name.
24
25
26
|
# File 'lib/githooks/section.rb', line 24
def name
@name
end
|
#success ⇒ Object
Also known as:
success?
Returns the value of attribute success.
24
25
26
|
# File 'lib/githooks/section.rb', line 24
def success
@success
end
|
Class Method Details
.key_from_name(name) ⇒ Object
30
31
32
|
# File 'lib/githooks/section.rb', line 30
def key_from_name(name)
name.to_s.underscore.to_sym
end
|
Instance Method Details
#<<(action) ⇒ Object
55
56
57
|
# File 'lib/githooks/section.rb', line 55
def <<(action)
@actions << action
end
|
#action(title, &block) ⇒ Object
128
129
130
131
132
|
# File 'lib/githooks/section.rb', line 128
def action(title, &block)
fail ArgumentError, 'expected block, received none' unless block_given?
@actions << Action.new(title, self, &block)
self
end
|
#actions ⇒ Object
Also known as:
__getobj__
overrides previous action method to only return actions that have a non-empty manifest
50
51
52
|
# File 'lib/githooks/section.rb', line 50
def actions
@actions.reject { |action| action.manifest.empty? }
end
|
#colored_name(phase = GitHooks::HOOK_NAME) ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/githooks/section.rb', line 76
def colored_name(phase = GitHooks::HOOK_NAME)
title = name(phase)
return title.color_skipped! if @actions.all?(&:skipped?)
return title.color_unknown! unless completed?
return title.color_failure! unless success?
title.color_success!
end
|
#completed? ⇒ Boolean
64
65
66
|
# File 'lib/githooks/section.rb', line 64
def completed?
finished? && @actions.all?(&:finished?)
end
|
#config_file(*path_components) ⇒ Object
109
110
111
|
# File 'lib/githooks/section.rb', line 109
def config_file(*path_components)
config_path.join(*path_components)
end
|
#config_path ⇒ Object
105
106
107
|
# File 'lib/githooks/section.rb', line 105
def config_path
GitHooks.hooks_root.join('configs')
end
|
84
85
86
|
# File 'lib/githooks/section.rb', line 84
def key_name
self.class.key_from_name(@name)
end
|
#lib_file(*path_components) ⇒ Object
117
118
119
|
# File 'lib/githooks/section.rb', line 117
def lib_file(*path_components)
lib_path.join(*path_components)
end
|
113
114
115
|
# File 'lib/githooks/section.rb', line 113
def lib_path
GitHooks.hooks_root.join('lib')
end
|
#limit(type) ⇒ Object
121
122
123
124
125
126
|
# File 'lib/githooks/section.rb', line 121
def limit(type)
unless @limiters.include? type
@limiters[type] ||= Repository::Limiter.new(type)
end
@limiters[type]
end
|
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
# File 'lib/githooks/section.rb', line 88
def run
running!
begin
time_start = Time.now
actions.collect { |action|
@success &= action.run.tap { |r|
STDERR.puts "#{action.title} -> #{r.inspect}" if GitHooks.debug?
}
}.all?
ensure
@benchmark = Time.now - time_start
finished!
end
end
|
Returns the value of attribute name.
26
27
28
|
# File 'lib/githooks/section.rb', line 26
def name
@name
end
|
#wait_count ⇒ Object
68
69
70
|
# File 'lib/githooks/section.rb', line 68
def wait_count
@actions.count(&:waiting?)
end
|