Name | Total Lines | Lines of Code | Total Coverage | Code Coverage |
---|---|---|---|---|
lib/bee_properties.rb | 116 | 59 | 100.00%
|
100.00%
|
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.
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 |
18 module Bee |
19 |
20 # Class to manage properties. |
21 class Properties |
22 |
23 include Bee::Util::BuildErrorMixin |
24 |
25 # System properties |
26 SYSTEM_PROPERTIES = [:base, :here] |
27 |
28 # Key for properties entry. |
29 KEY = 'properties' |
30 |
31 # Properties expressions |
32 attr_reader :expressions |
33 |
34 # Constructor. |
35 # - properties: properties as a hash. |
36 def initialize(properties={}) |
37 @expressions = {} |
38 check_properties(properties) |
39 set_properties(properties, false) |
40 end |
41 |
42 # Write new properties with passed expressions. |
43 # - properties: properties as a hash. |
44 def write(properties) |
45 check_properties(properties) |
46 set_properties(properties, false) |
47 end |
48 |
49 # Overwrite properties with those passed. |
50 # - properties: properties as a hash. |
51 def overwrite(properties) |
52 check_properties(properties) |
53 set_properties(properties, true) |
54 end |
55 |
56 # Set default properties: if they are already defined, will raise an error. |
57 # - properties: default properties as a hash. |
58 def defaults(properties) |
59 set_properties(properties, true) |
60 end |
61 |
62 # Extend with properties of parent build. |
63 # - properties: properties of parent build as a hash. |
64 def extend(properties) |
65 check_properties_type(properties) |
66 for name in properties.keys |
67 @expressions[name] = properties[name] if !@expressions.include?(name) |
68 end |
69 end |
70 |
71 private |
72 |
73 # Check that properties are a hash and raise a BuildError if not. |
74 # - properties: properties to check as a hash. |
75 def check_properties_type(properties) |
76 error "Properties must be a hash" if not properties.kind_of?(Hash) |
77 end |
78 |
79 # Check properties for system ones: |
80 # - properties: properties expressions as a hash. |
81 def check_properties(properties) |
82 check_properties_type(properties) |
83 names = SYSTEM_PROPERTIES & properties.keys.map {|k| k.to_sym} |
84 if names.length > 1 |
85 error "#{names.join(' and ')} are reserved property names" |
86 elsif names.length > 0 |
87 error "#{names[0]} is a reserved property name" |
88 end |
89 end |
90 |
91 # Set properties. |
92 # - properties: properties as a hash. |
93 # - overwrite: tells if we can overwrite existing properties. |
94 def set_properties(properties, overwrite) |
95 check_properties_type(properties) |
96 for name in properties.keys |
97 expression = properties[name] |
98 set_property(name, expression, overwrite) |
99 end |
100 end |
101 |
102 # Set a given named property with an expression. |
103 # - name: property name (as a string or symbol). |
104 # - expression: property expression as a string. |
105 # - overwrite: tells if we can overwrite existing properties. |
106 def set_property(name, expression, overwrite) |
107 return if expression == nil |
108 name = name.to_sym |
109 error "Duplicate property definition: '#{name}'" if |
110 not overwrite and @expressions.has_key?(name) |
111 @expressions[name] = expression |
112 end |
113 |
114 end |
115 |
116 end |
Generated on Fri Oct 09 02:07:49 +0200 2015 with rcov 1.0.0