Bee C0 Coverage Information - RCov

lib/bee_targets.rb

Name Total Lines Lines of Code Total Coverage Code Coverage
lib/bee_targets.rb 186 126
91.94%
88.10%

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 require 'bee_util'
17 require 'bee_target'
18 
19 module Bee
20 
21   # Class to manage targets in a build.
22   class Targets
23 
24     include Bee::Util::BuildErrorMixin
25 
26     # The build.
27     attr_reader :build
28     # Targets hash by name.
29     attr_reader :hash
30     # List of targets that already ran.
31     attr_reader :already_run
32     # Default target.
33     attr_accessor :default
34     # Tells if defautl target was set in build file
35     attr_accessor :default_set
36     # Alias for targets
37     attr_accessor :alias
38     # Tells if alias was set in build file
39     attr_accessor :alias_set
40 
41     # Constructor.
42     # - build: build object.
43     def initialize(build)
44       @build = build
45       @hash = {}
46       @already_run = []
47     end
48 
49     # Add a new target.
50     # - object: object tree resulting from YAML build file parsing.
51     def add(object)
52       begin
53         target = Target.new(object, self)
54       rescue
55         error "Error parsing target '#{object[Bee::Target::KEY]}': #{$!}"
56       end
57       error "Duplicate target definition: '#{target.name}'" if
58         @hash.has_key?(target.name)
59       @hash[target.name] = [target]
60       # record first target for default
61     end
62 
63     # Extend parent targets.
64     # - parent: parent targets.
65     def extend(parent)
66       # set appropriate targets for targets of parent
67       for targets in parent.hash.values
68         for target in targets
69           target.targets = self
70         end
71       end
72       # insert parent targets before current ones
73       for name in parent.hash.keys
74         if @hash[name]
75           @hash[name] = parent.hash[name] + @hash[name]
76           # clean dependencies for redefined targets
77           for target in parent.hash[name]
78             target.depends.clear
79           end
80           # copy documentation of parent if target not documented
81           if not @hash[name].last.description
82             description = nil
83             for target in parent.hash[name]
84               description = target.description || description
85             end
86             @hash[name].last.description = description
87           end
88         else
89           @hash[name] = parent.hash[name]
90         end
91       end
92       # manage default target
93       if parent.default and !@default_set
94         @default = [] if !@default
95         @default += parent.default
96       end
97       @default = @default || parent.default
98       # manage aliases
99       @alias = {} if !@alias
100       if parent.alias
101         for key in parent.alias.keys
102           if !@alias_set.include?(key)
103             if @alias.has_key?(key)
104               @alias[key] = Array(@alias[key]) + Array(parent.alias[key])
105             else
106               @alias[key] = Array(parent.alias[key])
107             end
108           end
109         end
110       end
111     end
112 
113     # Run a given target.
114     # - target: the target to run.
115     # - dry: tells if we run in dry mode. Defaults to false.
116     def run_target(target, dry=false)
117       error "Target '#{target}' not found" if not @hash[target]
118       if not @already_run.include?(target)
119         @already_run << target
120         @hash[target].last.run(dry)
121       end
122     end
123 
124     # Run targets.
125     # - targets: list of target names to run.
126     def run(targets, dry)
127       targets = [] if targets == ''
128       targets = targets || []
129       targets = Array(targets)
130       if targets.length == 0
131         if @default
132           targets = @default
133         else
134           error "No default target given"
135         end
136       end
137       aliased_targets = []
138       for target in targets
139         if @alias and @alias.has_key?(target)
140           aliased_targets += Array(@alias[target])
141         else
142           aliased_targets << target
143         end
144       end
145       for target in aliased_targets
146         run_target(target, dry)
147         @already_run.clear
148       end
149     end
150 
151     # Call super target.
152     # - target: target to call super onto.
153     def call_super(target, dry=false)
154       index = @hash[target.name].index(target)
155       error "No super target to call for '#{target.name}'" if index == 0
156       index -= 1
157       @hash[target.name][index].run(dry)
158     end
159 
160     # Tells if a given target is last in hierarchy.
161     # - target: given target.
162     def is_last(target)
163       index = @hash[target.name].index(target)
164       last = @hash[target.name].size - 1
165       return index == last
166     end
167 
168     # Return targets description as a hash of descriptions indexed by
169     # target name. Dependencies are added after target description.
170     def description
171       description = {}
172       for name in @hash.keys
173         text = @hash[name].last.description
174         if @hash[name].last.depends and @hash[name].last.depends.length > 0
175           depends = ' [' + @hash[name].last.depends.join(', ') + ']'
176         else
177           depends = nil
178         end
179         description[name] = (text ? text : '') + (depends ? depends : '')
180       end
181       return description
182     end
183 
184   end
185 
186 end

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