Bee C0 Coverage Information - RCov

lib/bee_listener.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/bee_listener.rb 114 60
100.00%
100.00%

Key

Code reported as executed by Ruby looks like this...and this: this line is also marked as covered.Lines considered as run by rcov, but not reported by Ruby, look like this,and this: these lines were inferred by rcov (using simple heuristics).Finally, here's a line marked as not executed.

Coverage Details

1 # Copyright 2006-2012 Michel Casabianca <michel.casabianca@gmail.com>
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 require 'rubygems'
16 
17 module Bee
18 
19   # Listener called when build events are triggered. Calls formatter to print
20   # events on the console.
21   class Listener
22 
23     # Formatter used by listener.
24     attr_reader :formatter
25     # Build start time.
26     attr_reader :start_time
27     # Build end time.
28     attr_reader :end_time
29     # Build duration.
30     attr_reader :duration
31     # Build success.
32     attr_reader :successful
33     # Last target met.
34     attr_reader :last_target
35     # Last task met.
36     attr_reader :last_task
37     # Raised exception during build
38     attr_reader :exception
39 
40     # Constructor.
41     # - formatter: the formatter to use to output on console.
42     def initialize(formatter)
43       @formatter = formatter
44     end
45 
46     # Called when build is started.
47     # - build: the build object.
48     # - dry_run: tells if we are running in dry run.
49     def start(build, dry_run)
50       @start_time = Time.now
51       @end_time = nil
52       @duration = nil
53       @successful = nil
54       @last_target = nil
55       @last_task = nil
56       @formatter.print_build_started(build, dry_run)
57     end
58 
59     # Called when build is finished.
60     def stop()
61       stop_chrono()
62       @formatter.print_build_finished(@duration)
63     end
64 
65     # Called when a target is met.
66     # - target: the target object.
67     def target(target)
68       @last_target = target
69       @last_task = nil
70       @formatter.print_target(target)
71     end
72 
73     # Called when a task is met.
74     # - task: task source (shell, Ruby or task).
75     def task(task)
76       @last_task = task
77       @formatter.print_task(task)
78     end
79 
80     # Called when the build is a success.
81     def success()
82       @successful = true
83       @exception = nil
84     end
85 
86     # Called when an error was raised.
87     # - exception: raised exception.
88     def error(exception)
89       @successful = false
90       @exception = exception
91       if exception.kind_of?(Bee::Util::BuildError)
92         exception.target = @last_target if @last_target
93         exception.task = @last_task if @last_task
94       end
95     end
96 
97     # Recover from a previous error (catching it for instance).
98     def recover()
99       @successful = true
100       @exception = nil
101     end
102 
103     private
104 
105     # Stop chronometer, write build end time and build duration.
106     def stop_chrono()
107       @end_time = Time.now
108       @duration = @end_time - @start_time
109       @duration = (@duration * 1000).round / 1000
110     end
111 
112   end
113 
114 end

Generated on Fri Oct 09 02:07:49 +0200 2015 with rcov 1.0.0