chef-utils 18.0.169 → 18.0.172

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +201 -201
  3. data/Rakefile +15 -15
  4. data/chef-utils.gemspec +50 -50
  5. data/lib/chef-utils/dist.rb +154 -154
  6. data/lib/chef-utils/dsl/architecture.rb +150 -150
  7. data/lib/chef-utils/dsl/cloud.rb +155 -155
  8. data/lib/chef-utils/dsl/default_paths.rb +60 -60
  9. data/lib/chef-utils/dsl/introspection.rb +134 -134
  10. data/lib/chef-utils/dsl/os.rb +58 -58
  11. data/lib/chef-utils/dsl/path_sanity.rb +39 -39
  12. data/lib/chef-utils/dsl/platform.rb +387 -387
  13. data/lib/chef-utils/dsl/platform_family.rb +360 -360
  14. data/lib/chef-utils/dsl/platform_version.rb +41 -41
  15. data/lib/chef-utils/dsl/service.rb +112 -112
  16. data/lib/chef-utils/dsl/train_helpers.rb +87 -87
  17. data/lib/chef-utils/dsl/virtualization.rb +272 -272
  18. data/lib/chef-utils/dsl/which.rb +123 -123
  19. data/lib/chef-utils/dsl/windows.rb +86 -86
  20. data/lib/chef-utils/internal.rb +114 -114
  21. data/lib/chef-utils/mash.rb +263 -263
  22. data/lib/chef-utils/parallel_map.rb +131 -131
  23. data/lib/chef-utils/version.rb +20 -20
  24. data/lib/chef-utils/version_string.rb +160 -160
  25. data/lib/chef-utils.rb +53 -53
  26. data/spec/spec_helper.rb +100 -100
  27. data/spec/unit/dsl/architecture_spec.rb +151 -151
  28. data/spec/unit/dsl/cloud_spec.rb +93 -93
  29. data/spec/unit/dsl/dsl_spec.rb +34 -34
  30. data/spec/unit/dsl/introspection_spec.rb +201 -201
  31. data/spec/unit/dsl/os_spec.rb +175 -175
  32. data/spec/unit/dsl/path_sanity_spec.rb +86 -86
  33. data/spec/unit/dsl/platform_family_spec.rb +235 -235
  34. data/spec/unit/dsl/platform_spec.rb +252 -252
  35. data/spec/unit/dsl/service_spec.rb +117 -117
  36. data/spec/unit/dsl/virtualization_spec.rb +75 -75
  37. data/spec/unit/dsl/which_spec.rb +171 -171
  38. data/spec/unit/dsl/windows_spec.rb +84 -84
  39. data/spec/unit/mash_spec.rb +51 -51
  40. data/spec/unit/parallel_map_spec.rb +156 -156
  41. metadata +7 -7
@@ -1,263 +1,263 @@
1
- # frozen_string_literal: true
2
- # Copyright 2009-2016, Dan Kubb
3
-
4
- # Permission is hereby granted, free of charge, to any person obtaining
5
- # a copy of this software and associated documentation files (the
6
- # "Software"), to deal in the Software without restriction, including
7
- # without limitation the rights to use, copy, modify, merge, publish,
8
- # distribute, sublicense, and/or sell copies of the Software, and to
9
- # permit persons to whom the Software is furnished to do so, subject to
10
- # the following conditions:
11
-
12
- # The above copyright notice and this permission notice shall be
13
- # included in all copies or substantial portions of the Software.
14
-
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
-
23
- # ---
24
- # ---
25
-
26
- # Some portions of blank.rb and mash.rb are verbatim copies of software
27
- # licensed under the MIT license. That license is included below:
28
-
29
- # Copyright 2005-2016, David Heinemeier Hansson
30
-
31
- # Permission is hereby granted, free of charge, to any person obtaining
32
- # a copy of this software and associated documentation files (the
33
- # "Software"), to deal in the Software without restriction, including
34
- # without limitation the rights to use, copy, modify, merge, publish,
35
- # distribute, sublicense, and/or sell copies of the Software, and to
36
- # permit persons to whom the Software is furnished to do so, subject to
37
- # the following conditions:
38
-
39
- # The above copyright notice and this permission notice shall be
40
- # included in all copies or substantial portions of the Software.
41
-
42
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
46
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
47
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
48
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
-
50
- # This class has dubious semantics and we only have it so that people can write
51
- # params[:key] instead of params['key'].
52
- module ChefUtils
53
- class Mash < Hash
54
-
55
- # @param constructor<Object>
56
- # The default value for the mash. Defaults to an empty hash.
57
- #
58
- # @details [Alternatives]
59
- # If constructor is a Hash, a new mash will be created based on the keys of
60
- # the hash and no default value will be set.
61
- def initialize(constructor = {})
62
- if constructor.is_a?(Hash)
63
- super()
64
- update(constructor)
65
- else
66
- super(constructor)
67
- end
68
- end
69
-
70
- # @param orig<Object> Mash being copied
71
- #
72
- # @return [Object] A new copied Mash
73
- def initialize_copy(orig)
74
- super
75
- # Handle nested values
76
- each do |k, v|
77
- if v.is_a?(Mash) || v.is_a?(Array)
78
- self[k] = v.dup
79
- end
80
- end
81
- self
82
- end
83
-
84
- # @param key<Object> The default value for the mash. Defaults to nil.
85
- #
86
- # @details [Alternatives]
87
- # If key is a Symbol and it is a key in the mash, then the default value will
88
- # be set to the value matching the key.
89
- def default(key = nil)
90
- if key.is_a?(Symbol) && include?(key = key.to_s)
91
- self[key]
92
- else
93
- super
94
- end
95
- end
96
-
97
- unless method_defined?(:regular_reader)
98
- alias_method :regular_reader, :[]
99
- end
100
-
101
- unless method_defined?(:regular_writer)
102
- alias_method :regular_writer, :[]=
103
- end
104
-
105
- unless method_defined?(:regular_update)
106
- alias_method :regular_update, :update
107
- end
108
-
109
- unless method_defined?(:regular_clear)
110
- alias_method :regular_clear, :clear
111
- end
112
-
113
- unless method_defined?(:regular_delete)
114
- alias_method :regular_delete, :delete
115
- end
116
-
117
- # @param key<Object> The key to get.
118
- def [](key)
119
- regular_reader(key)
120
- end
121
-
122
- # @param key<Object> The key to set.
123
- # @param value<Object>
124
- # The value to set the key to.
125
- #
126
- # @see Mash#convert_key
127
- # @see Mash#convert_value
128
- def []=(key, value)
129
- regular_writer(convert_key(key), convert_value(value))
130
- end
131
-
132
- # internal API for use by Chef's deep merge cache
133
- # @api private
134
- def internal_get(key)
135
- regular_reader(key)
136
- end
137
-
138
- # internal API for use by Chef's deep merge cache
139
- # @api private
140
- def internal_set(key, value)
141
- regular_writer(key, convert_value(value))
142
- end
143
-
144
- # @param other_hash<Hash>
145
- # A hash to update values in the mash with. The keys and the values will be
146
- # converted to Mash format.
147
- #
148
- # @return [Mash] The updated mash.
149
- def update(other_hash)
150
- other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
151
- self
152
- end
153
-
154
- alias_method :merge!, :update
155
-
156
- # @param key<Object> The key to check for. This will be run through convert_key.
157
- #
158
- # @return [Boolean] True if the key exists in the mash.
159
- def key?(key)
160
- super(convert_key(key))
161
- end
162
-
163
- # def include? def has_key? def member?
164
- alias_method :include?, :key?
165
- alias_method :has_key?, :key?
166
- alias_method :member?, :key?
167
-
168
- # @param key<Object> The key to fetch. This will be run through convert_key.
169
- # @param *extras<Array> Default value.
170
- #
171
- # @return [Object] The value at key or the default value.
172
- def fetch(key, *extras)
173
- super(convert_key(key), *extras)
174
- end
175
-
176
- # @param *indices<Array>
177
- # The keys to retrieve values for. These will be run through +convert_key+.
178
- #
179
- # @return [Array] The values at each of the provided keys
180
- def values_at(*indices)
181
- indices.collect { |key| self[convert_key(key)] }
182
- end
183
-
184
- # @param hash<Hash> The hash to merge with the mash.
185
- #
186
- # @return [Mash] A new mash with the hash values merged in.
187
- def merge(hash)
188
- dup.update(hash)
189
- end
190
-
191
- # @param key<Object>
192
- # The key to delete from the mash.\
193
- def delete(key)
194
- super(convert_key(key))
195
- end
196
-
197
- # @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
198
- #
199
- # @return [Mash] A new mash without the selected keys.
200
- #
201
- # @example
202
- # { :one => 1, :two => 2, :three => 3 }.except(:one)
203
- # #=> { "two" => 2, "three" => 3 }
204
- def except(*keys)
205
- super(*keys.map { |k| convert_key(k) })
206
- end
207
-
208
- # Used to provide the same interface as Hash.
209
- #
210
- # @return [Mash] This mash unchanged.
211
- def stringify_keys!; self end
212
-
213
- # @return [Hash] The mash as a Hash with symbolized keys.
214
- def symbolize_keys
215
- h = Hash.new(default)
216
- each { |key, val| h[key.to_sym] = val }
217
- h
218
- end
219
-
220
- # @return [Hash] The mash as a Hash with string keys.
221
- def to_hash
222
- Hash.new(default).merge(self)
223
- end
224
-
225
- # @return [Mash] Convert a Hash into a Mash
226
- # The input Hash's default value is maintained
227
- def self.from_hash(hash)
228
- mash = Mash.new(hash)
229
- mash.default = hash.default
230
- mash
231
- end
232
-
233
- protected
234
-
235
- # @param key<Object> The key to convert.
236
- #
237
- # @param [Object]
238
- # The converted key. If the key was a symbol, it will be converted to a
239
- # string.
240
- #
241
- # @api private
242
- def convert_key(key)
243
- key.is_a?(Symbol) ? key.to_s : key
244
- end
245
-
246
- # @param value<Object> The value to convert.
247
- #
248
- # @return [Object]
249
- # The converted value. A Hash or an Array of hashes, will be converted to
250
- # their Mash equivalents.
251
- #
252
- # @api private
253
- def convert_value(value)
254
- if value.class == Hash
255
- Mash.from_hash(value)
256
- elsif value.is_a?(Array)
257
- value.collect { |e| convert_value(e) }
258
- else
259
- value
260
- end
261
- end
262
- end
263
- end
1
+ # frozen_string_literal: true
2
+ # Copyright 2009-2016, Dan Kubb
3
+
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ # ---
24
+ # ---
25
+
26
+ # Some portions of blank.rb and mash.rb are verbatim copies of software
27
+ # licensed under the MIT license. That license is included below:
28
+
29
+ # Copyright 2005-2016, David Heinemeier Hansson
30
+
31
+ # Permission is hereby granted, free of charge, to any person obtaining
32
+ # a copy of this software and associated documentation files (the
33
+ # "Software"), to deal in the Software without restriction, including
34
+ # without limitation the rights to use, copy, modify, merge, publish,
35
+ # distribute, sublicense, and/or sell copies of the Software, and to
36
+ # permit persons to whom the Software is furnished to do so, subject to
37
+ # the following conditions:
38
+
39
+ # The above copyright notice and this permission notice shall be
40
+ # included in all copies or substantial portions of the Software.
41
+
42
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
43
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
45
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
46
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
47
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
48
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
49
+
50
+ # This class has dubious semantics and we only have it so that people can write
51
+ # params[:key] instead of params['key'].
52
+ module ChefUtils
53
+ class Mash < Hash
54
+
55
+ # @param constructor<Object>
56
+ # The default value for the mash. Defaults to an empty hash.
57
+ #
58
+ # @details [Alternatives]
59
+ # If constructor is a Hash, a new mash will be created based on the keys of
60
+ # the hash and no default value will be set.
61
+ def initialize(constructor = {})
62
+ if constructor.is_a?(Hash)
63
+ super()
64
+ update(constructor)
65
+ else
66
+ super(constructor)
67
+ end
68
+ end
69
+
70
+ # @param orig<Object> Mash being copied
71
+ #
72
+ # @return [Object] A new copied Mash
73
+ def initialize_copy(orig)
74
+ super
75
+ # Handle nested values
76
+ each do |k, v|
77
+ if v.is_a?(Mash) || v.is_a?(Array)
78
+ self[k] = v.dup
79
+ end
80
+ end
81
+ self
82
+ end
83
+
84
+ # @param key<Object> The default value for the mash. Defaults to nil.
85
+ #
86
+ # @details [Alternatives]
87
+ # If key is a Symbol and it is a key in the mash, then the default value will
88
+ # be set to the value matching the key.
89
+ def default(key = nil)
90
+ if key.is_a?(Symbol) && include?(key = key.to_s)
91
+ self[key]
92
+ else
93
+ super
94
+ end
95
+ end
96
+
97
+ unless method_defined?(:regular_reader)
98
+ alias_method :regular_reader, :[]
99
+ end
100
+
101
+ unless method_defined?(:regular_writer)
102
+ alias_method :regular_writer, :[]=
103
+ end
104
+
105
+ unless method_defined?(:regular_update)
106
+ alias_method :regular_update, :update
107
+ end
108
+
109
+ unless method_defined?(:regular_clear)
110
+ alias_method :regular_clear, :clear
111
+ end
112
+
113
+ unless method_defined?(:regular_delete)
114
+ alias_method :regular_delete, :delete
115
+ end
116
+
117
+ # @param key<Object> The key to get.
118
+ def [](key)
119
+ regular_reader(key)
120
+ end
121
+
122
+ # @param key<Object> The key to set.
123
+ # @param value<Object>
124
+ # The value to set the key to.
125
+ #
126
+ # @see Mash#convert_key
127
+ # @see Mash#convert_value
128
+ def []=(key, value)
129
+ regular_writer(convert_key(key), convert_value(value))
130
+ end
131
+
132
+ # internal API for use by Chef's deep merge cache
133
+ # @api private
134
+ def internal_get(key)
135
+ regular_reader(key)
136
+ end
137
+
138
+ # internal API for use by Chef's deep merge cache
139
+ # @api private
140
+ def internal_set(key, value)
141
+ regular_writer(key, convert_value(value))
142
+ end
143
+
144
+ # @param other_hash<Hash>
145
+ # A hash to update values in the mash with. The keys and the values will be
146
+ # converted to Mash format.
147
+ #
148
+ # @return [Mash] The updated mash.
149
+ def update(other_hash)
150
+ other_hash.each_pair { |key, value| regular_writer(convert_key(key), convert_value(value)) }
151
+ self
152
+ end
153
+
154
+ alias_method :merge!, :update
155
+
156
+ # @param key<Object> The key to check for. This will be run through convert_key.
157
+ #
158
+ # @return [Boolean] True if the key exists in the mash.
159
+ def key?(key)
160
+ super(convert_key(key))
161
+ end
162
+
163
+ # def include? def has_key? def member?
164
+ alias_method :include?, :key?
165
+ alias_method :has_key?, :key?
166
+ alias_method :member?, :key?
167
+
168
+ # @param key<Object> The key to fetch. This will be run through convert_key.
169
+ # @param *extras<Array> Default value.
170
+ #
171
+ # @return [Object] The value at key or the default value.
172
+ def fetch(key, *extras)
173
+ super(convert_key(key), *extras)
174
+ end
175
+
176
+ # @param *indices<Array>
177
+ # The keys to retrieve values for. These will be run through +convert_key+.
178
+ #
179
+ # @return [Array] The values at each of the provided keys
180
+ def values_at(*indices)
181
+ indices.collect { |key| self[convert_key(key)] }
182
+ end
183
+
184
+ # @param hash<Hash> The hash to merge with the mash.
185
+ #
186
+ # @return [Mash] A new mash with the hash values merged in.
187
+ def merge(hash)
188
+ dup.update(hash)
189
+ end
190
+
191
+ # @param key<Object>
192
+ # The key to delete from the mash.\
193
+ def delete(key)
194
+ super(convert_key(key))
195
+ end
196
+
197
+ # @param *rejected<Array[(String, Symbol)] The mash keys to exclude.
198
+ #
199
+ # @return [Mash] A new mash without the selected keys.
200
+ #
201
+ # @example
202
+ # { :one => 1, :two => 2, :three => 3 }.except(:one)
203
+ # #=> { "two" => 2, "three" => 3 }
204
+ def except(*keys)
205
+ super(*keys.map { |k| convert_key(k) })
206
+ end
207
+
208
+ # Used to provide the same interface as Hash.
209
+ #
210
+ # @return [Mash] This mash unchanged.
211
+ def stringify_keys!; self end
212
+
213
+ # @return [Hash] The mash as a Hash with symbolized keys.
214
+ def symbolize_keys
215
+ h = Hash.new(default)
216
+ each { |key, val| h[key.to_sym] = val }
217
+ h
218
+ end
219
+
220
+ # @return [Hash] The mash as a Hash with string keys.
221
+ def to_hash
222
+ Hash.new(default).merge(self)
223
+ end
224
+
225
+ # @return [Mash] Convert a Hash into a Mash
226
+ # The input Hash's default value is maintained
227
+ def self.from_hash(hash)
228
+ mash = Mash.new(hash)
229
+ mash.default = hash.default
230
+ mash
231
+ end
232
+
233
+ protected
234
+
235
+ # @param key<Object> The key to convert.
236
+ #
237
+ # @param [Object]
238
+ # The converted key. If the key was a symbol, it will be converted to a
239
+ # string.
240
+ #
241
+ # @api private
242
+ def convert_key(key)
243
+ key.is_a?(Symbol) ? key.to_s : key
244
+ end
245
+
246
+ # @param value<Object> The value to convert.
247
+ #
248
+ # @return [Object]
249
+ # The converted value. A Hash or an Array of hashes, will be converted to
250
+ # their Mash equivalents.
251
+ #
252
+ # @api private
253
+ def convert_value(value)
254
+ if value.class == Hash
255
+ Mash.from_hash(value)
256
+ elsif value.is_a?(Array)
257
+ value.collect { |e| convert_value(e) }
258
+ else
259
+ value
260
+ end
261
+ end
262
+ end
263
+ end