Class: Bwoken::Formatter
- Inherits:
-
Object
show all
- Defined in:
- lib/bwoken/formatter.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
21
22
23
24
25
26
|
# File 'lib/bwoken/formatter.rb', line 21
def method_missing(method_name, *args, &block)
callback_method_sig = "_on_#{method_name}_callback"
if self.respond_to? callback_method_sig.to_sym
send(callback_method_sig, *args, &block)
end
end
|
Class Method Details
5
6
7
|
# File 'lib/bwoken/formatter.rb', line 5
def format stdout
new.format stdout
end
|
9
10
11
|
# File 'lib/bwoken/formatter.rb', line 9
def format_build stdout
new.format_build stdout
end
|
.on(name, &block) ⇒ Object
13
14
15
16
17
|
# File 'lib/bwoken/formatter.rb', line 13
def on name, &block
define_method "_on_#{name}_callback" do |*line|
block.call(*line)
end
end
|
Instance Method Details
61
62
63
64
65
66
67
68
69
|
# File 'lib/bwoken/formatter.rb', line 61
def format stdout
exit_status = 0
stdout.each_line do |line|
exit_status = line_demuxer line, exit_status
end
exit_status
end
|
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/bwoken/formatter.rb', line 71
def format_build stdout
out_string = ''
stdout.each_line do |line|
out_string << line
if line.length > 1
_on_build_line_callback(line)
end
end
out_string
end
|
#line_demuxer(line, exit_status) ⇒ Object
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/bwoken/formatter.rb', line 28
def line_demuxer line, exit_status
if line =~ /Instruments Trace Error/
exit_status = 1
_on_fail_callback(line)
elsif line =~ /^\d{4}/
tokens = line.split(' ')
if tokens[3] =~ /Pass/
_on_pass_callback(line)
elsif tokens[3] =~ /Start/
_on_start_callback(line)
elsif tokens[3] =~ /Fail/ || line =~ /Script threw an uncaught JavaScript error/
exit_status = 1
_on_fail_callback(line)
elsif tokens[3] =~ /Error/
_on_error_callback(line)
else
_on_debug_callback(line)
end
elsif line =~ /Instruments Trace Complete/
_on_complete_callback(line)
else
_on_other_callback(line)
end
exit_status
end
|