Class: GitHooker::Action
Defined Under Namespace
Classes: DSL
Constant Summary
TerminalColors::MARK_FAILURE, TerminalColors::MARK_SUCCESS, TerminalColors::MARK_UNKNOWN, TerminalColors::NORMAL
Instance Attribute Summary collapse
Instance Method Summary
collapse
#color
Constructor Details
#initialize(title, phase, &block) ⇒ Action
Returns a new instance of Action.
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/githooker/action.rb', line 11
def initialize(title, phase, &block)
raise ArgumentError, "Missing required block for Action#new" unless block_given?
phase = phase.to_s.to_sym
unless GitHooker::VALID_PHASES.include? phase
raise ArgumentError, "Phase must be one of #{GitHooker::VALID_PHASES.join(', ')}"
end
@title = title.to_s.titleize
@success = true
@phase = phase || :any
@errors = []
@warnings = []
@action = DSL.new(block)
waiting!
end
|
Instance Attribute Details
#errors ⇒ Object
Returns the value of attribute errors.
9
10
11
|
# File 'lib/githooker/action.rb', line 9
def errors
@errors
end
|
#phase ⇒ Object
Returns the value of attribute phase.
9
10
11
|
# File 'lib/githooker/action.rb', line 9
def phase
@phase
end
|
#success ⇒ Object
Returns the value of attribute success.
9
10
11
|
# File 'lib/githooker/action.rb', line 9
def success
@success
end
|
#title ⇒ Object
Returns the value of attribute title.
9
10
11
|
# File 'lib/githooker/action.rb', line 9
def title
@title
end
|
#warnings ⇒ Object
Returns the value of attribute warnings.
9
10
11
|
# File 'lib/githooker/action.rb', line 9
def warnings
@warnings
end
|
Instance Method Details
#colored_title ⇒ Object
29
30
31
|
# File 'lib/githooker/action.rb', line 29
def colored_title()
status_colorize title
end
|
#finished! ⇒ Object
41
|
# File 'lib/githooker/action.rb', line 41
def finished!() @status = :finished; end
|
#finished? ⇒ Boolean
40
|
# File 'lib/githooker/action.rb', line 40
def finished?() @status == :finished; end
|
#run ⇒ Object
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/githooker/action.rb', line 53
def run
warnings, errors = StringIO.new, StringIO.new
begin
running!
$stdout, $stderr = warnings, errors
@success &= @action.call
return @success
ensure
@errors = errors.tap {|e| e.rewind}.read.split(/\n(?:[\t ]*)/)
@warnings = warnings.tap {|w| w.rewind}.read.split(/\n(?:[\t ]*)/)
$stdout, $stderr = STDOUT, STDERR
finished!
end
end
|
#running! ⇒ Object
44
|
# File 'lib/githooker/action.rb', line 44
def running!() @status = :running; end
|
#running? ⇒ Boolean
43
|
# File 'lib/githooker/action.rb', line 43
def running?() @status == :running; end
|
#state_symbol ⇒ Object
33
34
35
36
|
# File 'lib/githooker/action.rb', line 33
def state_symbol
symbol = finished? ? (success? ? "✓" : 'X') : '?'
status_colorize symbol
end
|
#status_colorize(text) ⇒ Object
49
50
51
|
# File 'lib/githooker/action.rb', line 49
def status_colorize(text)
finished? ? (success? ? bright_green(text) : bright_red(text)) : dark_cyan(text)
end
|
#success? ⇒ Boolean
38
|
# File 'lib/githooker/action.rb', line 38
def success?() @success; end
|
#waiting! ⇒ Object
47
|
# File 'lib/githooker/action.rb', line 47
def waiting!() @status = :waiting; end
|
#waiting? ⇒ Boolean
46
|
# File 'lib/githooker/action.rb', line 46
def waiting?() @status == :waiting; end
|