compat_resource 12.5.10 → 12.5.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +8 -4
- data/files/lib/chef_compat.rb +1 -0
- data/files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb +324 -0
- data/files/lib/chef_compat/copied_from_chef/chef/provider.rb +20 -7
- data/files/lib/chef_compat/copied_from_chef/chef/resource.rb +3 -120
- data/files/lib/chef_compat/mixin/properties.rb +8 -0
- data/files/lib/chef_compat/monkeypatches/chef.rb +1 -1
- data/files/lib/chef_compat/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 945c69b844a9383c193df2623398c426f0022340
|
4
|
+
data.tar.gz: 1b6533381e1f85a1f12bd80042059f5ad2ea6ee5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e356b9380f8e99b432ab210d70134e1f6a711ef3b25db04f0998ae4cc83549fdb5b9a38c8fda4c0487a4718bfe26eb1c4a850e46333b3c84021893c8e009d97f
|
7
|
+
data.tar.gz: e398d09c2e35040aa9eff70979289126a322734157a5bae4b0207980df58e7fb1db5b07a13cca2375893c074a68d2cf195ad20e2bf4567ae28dbbec203ad0948
|
data/Rakefile
CHANGED
@@ -15,11 +15,15 @@ task default: :spec
|
|
15
15
|
#
|
16
16
|
CHEF_FILES = %w(chef/constants chef/delayed_evaluator chef/property
|
17
17
|
chef/resource chef/resource/action_class chef/provider
|
18
|
-
chef/mixin/params_validate)
|
19
|
-
SPEC_FILES = %w(unit/
|
18
|
+
chef/mixin/params_validate chef/mixin/properties)
|
19
|
+
SPEC_FILES = %w(unit/mixin/properties_spec.rb
|
20
|
+
unit/property_spec.rb
|
21
|
+
unit/property/state_spec.rb
|
22
|
+
unit/property/validation_spec.rb
|
20
23
|
integration/recipes/resource_action_spec.rb
|
21
24
|
integration/recipes/resource_converge_if_changed_spec.rb
|
22
|
-
integration/recipes/resource_load_spec.rb
|
25
|
+
integration/recipes/resource_load_spec.rb
|
26
|
+
)
|
23
27
|
KEEP_FUNCTIONS = {
|
24
28
|
'chef/resource' => %w(
|
25
29
|
initialize
|
@@ -49,7 +53,7 @@ KEEP_FUNCTIONS = {
|
|
49
53
|
),
|
50
54
|
}
|
51
55
|
KEEP_INCLUDES = {
|
52
|
-
'chef/resource' => %w(Chef::Mixin::ParamsValidate),
|
56
|
+
'chef/resource' => %w(Chef::Mixin::ParamsValidate Chef::Mixin::Properties),
|
53
57
|
'chef/provider' => [],
|
54
58
|
}
|
55
59
|
KEEP_CLASSES = {
|
data/files/lib/chef_compat.rb
CHANGED
@@ -0,0 +1,324 @@
|
|
1
|
+
require 'chef_compat/copied_from_chef'
|
2
|
+
class Chef
|
3
|
+
module ::ChefCompat
|
4
|
+
module CopiedFromChef
|
5
|
+
require 'chef_compat/copied_from_chef/chef/delayed_evaluator'
|
6
|
+
require 'chef_compat/copied_from_chef/chef/mixin/params_validate'
|
7
|
+
require 'chef_compat/copied_from_chef/chef/property'
|
8
|
+
|
9
|
+
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
10
|
+
module Mixin
|
11
|
+
if defined?(::Chef::Mixin)
|
12
|
+
require 'chef_compat/delegating_class'
|
13
|
+
extend DelegatingClass
|
14
|
+
@delegates_to = ::Chef::Mixin
|
15
|
+
end
|
16
|
+
module Properties
|
17
|
+
if defined?(::Chef::Mixin::Properties)
|
18
|
+
require 'chef_compat/delegating_class'
|
19
|
+
extend DelegatingClass
|
20
|
+
@delegates_to = ::Chef::Mixin::Properties
|
21
|
+
end
|
22
|
+
module ClassMethods
|
23
|
+
if defined?(::Chef::Mixin::Properties::ClassMethods)
|
24
|
+
require 'chef_compat/delegating_class'
|
25
|
+
extend DelegatingClass
|
26
|
+
@delegates_to = ::Chef::Mixin::Properties::ClassMethods
|
27
|
+
end
|
28
|
+
#
|
29
|
+
# The list of properties defined on this resource.
|
30
|
+
#
|
31
|
+
# Everything defined with `property` is in this list.
|
32
|
+
#
|
33
|
+
# @param include_superclass [Boolean] `true` to include properties defined
|
34
|
+
# on superclasses; `false` or `nil` to return the list of properties
|
35
|
+
# directly on this class.
|
36
|
+
#
|
37
|
+
# @return [Hash<Symbol,Property>] The list of property names and types.
|
38
|
+
#
|
39
|
+
def properties(include_superclass=true)
|
40
|
+
if include_superclass
|
41
|
+
result = {}
|
42
|
+
ancestors.reverse_each { |c| result.merge!(c.properties(false)) if c.respond_to?(:properties) }
|
43
|
+
result
|
44
|
+
else
|
45
|
+
@properties ||= {}
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
#
|
50
|
+
# Create a property on this resource class.
|
51
|
+
#
|
52
|
+
# If a superclass has this property, or if this property has already been
|
53
|
+
# defined by this resource, this will *override* the previous value.
|
54
|
+
#
|
55
|
+
# @param name [Symbol] The name of the property.
|
56
|
+
# @param type [Object,Array<Object>] The type(s) of this property.
|
57
|
+
# If present, this is prepended to the `is` validation option.
|
58
|
+
# @param options [Hash<Symbol,Object>] Validation options.
|
59
|
+
# @option options [Object,Array] :is An object, or list of
|
60
|
+
# objects, that must match the value using Ruby's `===` operator
|
61
|
+
# (`options[:is].any? { |v| v === value }`).
|
62
|
+
# @option options [Object,Array] :equal_to An object, or list
|
63
|
+
# of objects, that must be equal to the value using Ruby's `==`
|
64
|
+
# operator (`options[:is].any? { |v| v == value }`)
|
65
|
+
# @option options [Regexp,Array<Regexp>] :regex An object, or
|
66
|
+
# list of objects, that must match the value with `regex.match(value)`.
|
67
|
+
# @option options [Class,Array<Class>] :kind_of A class, or
|
68
|
+
# list of classes, that the value must be an instance of.
|
69
|
+
# @option options [Hash<String,Proc>] :callbacks A hash of
|
70
|
+
# messages -> procs, all of which match the value. The proc must
|
71
|
+
# return a truthy or falsey value (true means it matches).
|
72
|
+
# @option options [Symbol,Array<Symbol>] :respond_to A method
|
73
|
+
# name, or list of method names, the value must respond to.
|
74
|
+
# @option options [Symbol,Array<Symbol>] :cannot_be A property,
|
75
|
+
# or a list of properties, that the value cannot have (such as `:nil` or
|
76
|
+
# `:empty`). The method with a questionmark at the end is called on the
|
77
|
+
# value (e.g. `value.empty?`). If the value does not have this method,
|
78
|
+
# it is considered valid (i.e. if you don't respond to `empty?` we
|
79
|
+
# assume you are not empty).
|
80
|
+
# @option options [Proc] :coerce A proc which will be called to
|
81
|
+
# transform the user input to canonical form. The value is passed in,
|
82
|
+
# and the transformed value returned as output. Lazy values will *not*
|
83
|
+
# be passed to this method until after they are evaluated. Called in the
|
84
|
+
# context of the resource (meaning you can access other properties).
|
85
|
+
# @option options [Boolean] :required `true` if this property
|
86
|
+
# must be present; `false` otherwise. This is checked after the resource
|
87
|
+
# is fully initialized.
|
88
|
+
# @option options [Boolean] :name_property `true` if this
|
89
|
+
# property defaults to the same value as `name`. Equivalent to
|
90
|
+
# `default: lazy { name }`, except that #property_is_set? will
|
91
|
+
# return `true` if the property is set *or* if `name` is set.
|
92
|
+
# @option options [Boolean] :name_attribute Same as `name_property`.
|
93
|
+
# @option options [Object] :default The value this property
|
94
|
+
# will return if the user does not set one. If this is `lazy`, it will
|
95
|
+
# be run in the context of the instance (and able to access other
|
96
|
+
# properties).
|
97
|
+
# @option options [Boolean] :desired_state `true` if this property is
|
98
|
+
# part of desired state. Defaults to `true`.
|
99
|
+
# @option options [Boolean] :identity `true` if this property
|
100
|
+
# is part of object identity. Defaults to `false`.
|
101
|
+
#
|
102
|
+
# @example Bare property
|
103
|
+
# property :x
|
104
|
+
#
|
105
|
+
# @example With just a type
|
106
|
+
# property :x, String
|
107
|
+
#
|
108
|
+
# @example With just options
|
109
|
+
# property :x, default: 'hi'
|
110
|
+
#
|
111
|
+
# @example With type and options
|
112
|
+
# property :x, String, default: 'hi'
|
113
|
+
#
|
114
|
+
def property(name, type=NOT_PASSED, **options)
|
115
|
+
name = name.to_sym
|
116
|
+
|
117
|
+
options.each { |k,v| options[k.to_sym] = v if k.is_a?(String) }
|
118
|
+
|
119
|
+
options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
|
120
|
+
options.merge!(name: name, declared_in: self)
|
121
|
+
|
122
|
+
if type == NOT_PASSED
|
123
|
+
# If a type is not passed, the property derives from the
|
124
|
+
# superclass property (if any)
|
125
|
+
if properties.has_key?(name)
|
126
|
+
property = properties[name].derive(**options)
|
127
|
+
else
|
128
|
+
property = property_type(**options)
|
129
|
+
end
|
130
|
+
|
131
|
+
# If a Property is specified, derive a new one from that.
|
132
|
+
elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property)
|
133
|
+
property = type.derive(**options)
|
134
|
+
|
135
|
+
# If a primitive type was passed, combine it with "is"
|
136
|
+
else
|
137
|
+
if options[:is]
|
138
|
+
options[:is] = ([ type ] + [ options[:is] ]).flatten(1)
|
139
|
+
else
|
140
|
+
options[:is] = type
|
141
|
+
end
|
142
|
+
property = property_type(**options)
|
143
|
+
end
|
144
|
+
|
145
|
+
local_properties = properties(false)
|
146
|
+
local_properties[name] = property
|
147
|
+
|
148
|
+
property.emit_dsl
|
149
|
+
end
|
150
|
+
|
151
|
+
#
|
152
|
+
# Create a reusable property type that can be used in multiple properties
|
153
|
+
# in different resources.
|
154
|
+
#
|
155
|
+
# @param options [Hash<Symbol,Object>] Validation options. see #property for
|
156
|
+
# the list of options.
|
157
|
+
#
|
158
|
+
# @example
|
159
|
+
# property_type(default: 'hi')
|
160
|
+
#
|
161
|
+
def property_type(**options)
|
162
|
+
Property.derive(**options)
|
163
|
+
end
|
164
|
+
|
165
|
+
#
|
166
|
+
# Create a lazy value for assignment to a default value.
|
167
|
+
#
|
168
|
+
# @param block The block to run when the value is retrieved.
|
169
|
+
#
|
170
|
+
# @return [Chef::DelayedEvaluator] The lazy value
|
171
|
+
#
|
172
|
+
def lazy(&block)
|
173
|
+
DelayedEvaluator.new(&block)
|
174
|
+
end
|
175
|
+
|
176
|
+
#
|
177
|
+
# Get or set the list of desired state properties for this resource.
|
178
|
+
#
|
179
|
+
# State properties are properties that describe the desired state
|
180
|
+
# of the system, such as file permissions or ownership.
|
181
|
+
# In general, state properties are properties that could be populated by
|
182
|
+
# examining the state of the system (e.g., File.stat can tell you the
|
183
|
+
# permissions on an existing file). Contrarily, properties that are not
|
184
|
+
# "state properties" usually modify the way Chef itself behaves, for example
|
185
|
+
# by providing additional options for a package manager to use when
|
186
|
+
# installing a package.
|
187
|
+
#
|
188
|
+
# This list is used by the Chef client auditing system to extract
|
189
|
+
# information from resources to describe changes made to the system.
|
190
|
+
#
|
191
|
+
# This method is unnecessary when declaring properties with `property`;
|
192
|
+
# properties are added to state_properties by default, and can be turned off
|
193
|
+
# with `desired_state: false`.
|
194
|
+
#
|
195
|
+
# ```ruby
|
196
|
+
# property :x # part of desired state
|
197
|
+
# property :y, desired_state: false # not part of desired state
|
198
|
+
# ```
|
199
|
+
#
|
200
|
+
# @param names [Array<Symbol>] A list of property names to set as desired
|
201
|
+
# state.
|
202
|
+
#
|
203
|
+
# @return [Array<Property>] All properties in desired state.
|
204
|
+
#
|
205
|
+
def state_properties(*names)
|
206
|
+
if !names.empty?
|
207
|
+
names = names.map { |name| name.to_sym }.uniq
|
208
|
+
|
209
|
+
local_properties = properties(false)
|
210
|
+
# Add new properties to the list.
|
211
|
+
names.each do |name|
|
212
|
+
property = properties[name]
|
213
|
+
if !property
|
214
|
+
self.property name, instance_variable_name: false, desired_state: true
|
215
|
+
elsif !property.desired_state?
|
216
|
+
self.property name, desired_state: true
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
# If state_attrs *excludes* something which is currently desired state,
|
221
|
+
# mark it as desired_state: false.
|
222
|
+
local_properties.each do |name,property|
|
223
|
+
if property.desired_state? && !names.include?(name)
|
224
|
+
self.property name, desired_state: false
|
225
|
+
end
|
226
|
+
end
|
227
|
+
end
|
228
|
+
|
229
|
+
properties.values.select { |property| property.desired_state? }
|
230
|
+
end
|
231
|
+
|
232
|
+
#
|
233
|
+
# Set the identity of this resource to a particular set of properties.
|
234
|
+
#
|
235
|
+
# This drives #identity, which returns data that uniquely refers to a given
|
236
|
+
# resource on the given node (in such a way that it can be correlated
|
237
|
+
# across Chef runs).
|
238
|
+
#
|
239
|
+
# This method is unnecessary when declaring properties with `property`;
|
240
|
+
# properties can be added to identity during declaration with
|
241
|
+
# `identity: true`.
|
242
|
+
#
|
243
|
+
# ```ruby
|
244
|
+
# property :x, identity: true # part of identity
|
245
|
+
# property :y # not part of identity
|
246
|
+
# ```
|
247
|
+
#
|
248
|
+
# If no properties are marked as identity, "name" is considered the identity.
|
249
|
+
#
|
250
|
+
# @param names [Array<Symbol>] A list of property names to set as the identity.
|
251
|
+
#
|
252
|
+
# @return [Array<Property>] All identity properties.
|
253
|
+
#
|
254
|
+
def identity_properties(*names)
|
255
|
+
if !names.empty?
|
256
|
+
names = names.map { |name| name.to_sym }
|
257
|
+
|
258
|
+
# Add or change properties that are not part of the identity.
|
259
|
+
names.each do |name|
|
260
|
+
property = properties[name]
|
261
|
+
if !property
|
262
|
+
self.property name, instance_variable_name: false, identity: true
|
263
|
+
elsif !property.identity?
|
264
|
+
self.property name, identity: true
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
# If identity_properties *excludes* something which is currently part of
|
269
|
+
# the identity, mark it as identity: false.
|
270
|
+
properties.each do |name,property|
|
271
|
+
if property.identity? && !names.include?(name)
|
272
|
+
|
273
|
+
self.property name, identity: false
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
result = properties.values.select { |property| property.identity? }
|
279
|
+
result = [ properties[:name] ] if result.empty?
|
280
|
+
result
|
281
|
+
end
|
282
|
+
|
283
|
+
def included(other)
|
284
|
+
other.extend ClassMethods
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
def self.included(other)
|
289
|
+
other.extend ClassMethods
|
290
|
+
end
|
291
|
+
|
292
|
+
include Chef::Mixin::ParamsValidate
|
293
|
+
|
294
|
+
#
|
295
|
+
# Whether this property has been set (or whether it has a default that has
|
296
|
+
# been retrieved).
|
297
|
+
#
|
298
|
+
# @param name [Symbol] The name of the property.
|
299
|
+
# @return [Boolean] `true` if the property has been set.
|
300
|
+
#
|
301
|
+
def property_is_set?(name)
|
302
|
+
property = self.class.properties[name.to_sym]
|
303
|
+
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
304
|
+
property.is_set?(self)
|
305
|
+
end
|
306
|
+
|
307
|
+
#
|
308
|
+
# Clear this property as if it had never been set. It will thereafter return
|
309
|
+
# the default.
|
310
|
+
# been retrieved).
|
311
|
+
#
|
312
|
+
# @param name [Symbol] The name of the property.
|
313
|
+
#
|
314
|
+
def reset_property(name)
|
315
|
+
property = self.class.properties[name.to_sym]
|
316
|
+
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
317
|
+
property.reset(self)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
end
|
321
|
+
end
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
@@ -28,26 +28,39 @@ super if defined?(::Chef::Provider)
|
|
28
28
|
specified_properties = properties.select { |property| new_resource.property_is_set?(property) }
|
29
29
|
modified = specified_properties.select { |p| new_resource.send(p) != current_resource.send(p) }
|
30
30
|
if modified.empty?
|
31
|
-
|
31
|
+
properties_str = if sensitive
|
32
|
+
specified_properties.join(", ")
|
33
|
+
else
|
34
|
+
specified_properties.map { |p| "#{p}=#{new_resource.send(p).inspect}" }.join(", ")
|
35
|
+
end
|
36
|
+
Chef::Log.debug("Skipping update of #{new_resource.to_s}: has not changed any of the specified properties #{properties_str}.")
|
32
37
|
return false
|
33
38
|
end
|
34
39
|
|
35
40
|
# Print the pretty green text and run the block
|
36
41
|
property_size = modified.map { |p| p.size }.max
|
37
|
-
modified
|
42
|
+
modified.map! do |p|
|
43
|
+
properties_str = if sensitive
|
44
|
+
'(suppressed sensitive property)'
|
45
|
+
else
|
46
|
+
"#{new_resource.send(p).inspect} (was #{current_resource.send(p).inspect})"
|
47
|
+
end
|
48
|
+
" set #{p.to_s.ljust(property_size)} to #{properties_str}"
|
49
|
+
end
|
38
50
|
converge_by([ "update #{current_resource.identity}" ] + modified, &converge_block)
|
39
51
|
|
40
52
|
else
|
41
53
|
# The resource doesn't exist. Mark that we are *creating* this, and
|
42
54
|
# write down any properties we are setting.
|
43
55
|
property_size = properties.map { |p| p.size }.max
|
44
|
-
created =
|
45
|
-
|
46
|
-
if
|
47
|
-
|
56
|
+
created = properties.map do |property|
|
57
|
+
default = ' (default value)' unless new_resource.property_is_set?(property)
|
58
|
+
properties_str = if sensitive
|
59
|
+
'(suppressed sensitive property)'
|
48
60
|
else
|
49
|
-
|
61
|
+
new_resource.send(property).inspect
|
50
62
|
end
|
63
|
+
" set #{property.to_s.ljust(property_size)} to #{properties_str}#{default}"
|
51
64
|
end
|
52
65
|
|
53
66
|
converge_by([ "create #{new_resource.identity}" ] + created, &converge_block)
|
@@ -2,10 +2,12 @@ require 'chef_compat/copied_from_chef'
|
|
2
2
|
class Chef
|
3
3
|
module ::ChefCompat
|
4
4
|
module CopiedFromChef
|
5
|
-
require 'chef_compat/copied_from_chef/chef/mixin/params_validate'
|
6
5
|
require 'chef_compat/copied_from_chef/chef/resource/action_class'
|
6
|
+
require 'chef_compat/copied_from_chef/chef/mixin/properties'
|
7
7
|
class Chef < (defined?(::Chef) ? ::Chef : Object)
|
8
8
|
class Resource < (defined?(::Chef::Resource) ? ::Chef::Resource : Object)
|
9
|
+
include Chef::Mixin::Properties
|
10
|
+
property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(', ') : v.to_s }, desired_state: false
|
9
11
|
def initialize(name, run_context=nil)
|
10
12
|
super if defined?(::Chef::Resource)
|
11
13
|
name(name) unless name.nil?
|
@@ -35,18 +37,6 @@ super if defined?(::Chef::Resource)
|
|
35
37
|
@elapsed_time = 0
|
36
38
|
@sensitive = false
|
37
39
|
end
|
38
|
-
def self.properties(include_superclass=true)
|
39
|
-
@properties ||= {}
|
40
|
-
if include_superclass
|
41
|
-
if superclass.respond_to?(:properties)
|
42
|
-
superclass.properties.merge(@properties)
|
43
|
-
else
|
44
|
-
@properties.dup
|
45
|
-
end
|
46
|
-
else
|
47
|
-
@properties
|
48
|
-
end
|
49
|
-
end
|
50
40
|
def action(arg=nil)
|
51
41
|
if arg
|
52
42
|
arg = Array(arg).map(&:to_sym)
|
@@ -82,113 +72,6 @@ super if defined?(::Chef::Resource)
|
|
82
72
|
return result.values.first if identity_properties.size == 1
|
83
73
|
result
|
84
74
|
end
|
85
|
-
include Chef::Mixin::ParamsValidate
|
86
|
-
def self.property(name, type=NOT_PASSED, **options)
|
87
|
-
name = name.to_sym
|
88
|
-
|
89
|
-
options.each { |k,v| options[k.to_sym] = v if k.is_a?(String) }
|
90
|
-
|
91
|
-
options[:instance_variable_name] = :"@#{name}" if !options.has_key?(:instance_variable_name)
|
92
|
-
options.merge!(name: name, declared_in: self)
|
93
|
-
|
94
|
-
if type == NOT_PASSED
|
95
|
-
# If a type is not passed, the property derives from the
|
96
|
-
# superclass property (if any)
|
97
|
-
if properties.has_key?(name)
|
98
|
-
property = properties[name].derive(**options)
|
99
|
-
else
|
100
|
-
property = property_type(**options)
|
101
|
-
end
|
102
|
-
|
103
|
-
# If a Property is specified, derive a new one from that.
|
104
|
-
elsif type.is_a?(Property) || (type.is_a?(Class) && type <= Property)
|
105
|
-
property = type.derive(**options)
|
106
|
-
|
107
|
-
# If a primitive type was passed, combine it with "is"
|
108
|
-
else
|
109
|
-
if options[:is]
|
110
|
-
options[:is] = ([ type ] + [ options[:is] ]).flatten(1)
|
111
|
-
else
|
112
|
-
options[:is] = type
|
113
|
-
end
|
114
|
-
property = property_type(**options)
|
115
|
-
end
|
116
|
-
|
117
|
-
local_properties = properties(false)
|
118
|
-
local_properties[name] = property
|
119
|
-
|
120
|
-
property.emit_dsl
|
121
|
-
end
|
122
|
-
def self.property_type(**options)
|
123
|
-
Property.derive(**options)
|
124
|
-
end
|
125
|
-
property :name, String, coerce: proc { |v| v.is_a?(Array) ? v.join(', ') : v.to_s }, desired_state: false
|
126
|
-
def property_is_set?(name)
|
127
|
-
property = self.class.properties[name.to_sym]
|
128
|
-
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
129
|
-
property.is_set?(self)
|
130
|
-
end
|
131
|
-
def reset_property(name)
|
132
|
-
property = self.class.properties[name.to_sym]
|
133
|
-
raise ArgumentError, "Property #{name} is not defined in class #{self}" if !property
|
134
|
-
property.reset(self)
|
135
|
-
end
|
136
|
-
def self.lazy(&block)
|
137
|
-
DelayedEvaluator.new(&block)
|
138
|
-
end
|
139
|
-
def self.state_properties(*names)
|
140
|
-
if !names.empty?
|
141
|
-
names = names.map { |name| name.to_sym }.uniq
|
142
|
-
|
143
|
-
local_properties = properties(false)
|
144
|
-
# Add new properties to the list.
|
145
|
-
names.each do |name|
|
146
|
-
property = properties[name]
|
147
|
-
if !property
|
148
|
-
self.property name, instance_variable_name: false, desired_state: true
|
149
|
-
elsif !property.desired_state?
|
150
|
-
self.property name, desired_state: true
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
# If state_attrs *excludes* something which is currently desired state,
|
155
|
-
# mark it as desired_state: false.
|
156
|
-
local_properties.each do |name,property|
|
157
|
-
if property.desired_state? && !names.include?(name)
|
158
|
-
self.property name, desired_state: false
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
properties.values.select { |property| property.desired_state? }
|
164
|
-
end
|
165
|
-
def self.identity_properties(*names)
|
166
|
-
if !names.empty?
|
167
|
-
names = names.map { |name| name.to_sym }
|
168
|
-
|
169
|
-
# Add or change properties that are not part of the identity.
|
170
|
-
names.each do |name|
|
171
|
-
property = properties[name]
|
172
|
-
if !property
|
173
|
-
self.property name, instance_variable_name: false, identity: true
|
174
|
-
elsif !property.identity?
|
175
|
-
self.property name, identity: true
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
# If identity_properties *excludes* something which is currently part of
|
180
|
-
# the identity, mark it as identity: false.
|
181
|
-
properties.each do |name,property|
|
182
|
-
if property.identity? && !names.include?(name)
|
183
|
-
self.property name, identity: false
|
184
|
-
end
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
result = properties.values.select { |property| property.identity? }
|
189
|
-
result = [ properties[:name] ] if result.empty?
|
190
|
-
result
|
191
|
-
end
|
192
75
|
def self.identity_property(name=nil)
|
193
76
|
result = identity_properties(*Array(name))
|
194
77
|
if result.size > 1
|
@@ -3,7 +3,7 @@ class Chef
|
|
3
3
|
# Earlier versions of Chef didn't have this message
|
4
4
|
module ChefCompatDeprecation
|
5
5
|
def log_deprecation(message, location=nil)
|
6
|
-
if superclass.
|
6
|
+
if superclass.method(:log_deprecation).owner != ChefCompatDeprecation
|
7
7
|
if !location
|
8
8
|
# Pick the first caller that is *not* part of the Chef or ChefCompat gem,
|
9
9
|
# that's the thing the user wrote.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compat_resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 12.5.
|
4
|
+
version: 12.5.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Keiser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -96,11 +96,13 @@ files:
|
|
96
96
|
- files/lib/chef_compat/copied_from_chef/chef/constants.rb
|
97
97
|
- files/lib/chef_compat/copied_from_chef/chef/delayed_evaluator.rb
|
98
98
|
- files/lib/chef_compat/copied_from_chef/chef/mixin/params_validate.rb
|
99
|
+
- files/lib/chef_compat/copied_from_chef/chef/mixin/properties.rb
|
99
100
|
- files/lib/chef_compat/copied_from_chef/chef/property.rb
|
100
101
|
- files/lib/chef_compat/copied_from_chef/chef/provider.rb
|
101
102
|
- files/lib/chef_compat/copied_from_chef/chef/resource.rb
|
102
103
|
- files/lib/chef_compat/copied_from_chef/chef/resource/action_class.rb
|
103
104
|
- files/lib/chef_compat/delegating_class.rb
|
105
|
+
- files/lib/chef_compat/mixin/properties.rb
|
104
106
|
- files/lib/chef_compat/monkeypatches.rb
|
105
107
|
- files/lib/chef_compat/monkeypatches/chef.rb
|
106
108
|
- files/lib/chef_compat/monkeypatches/chef/exceptions.rb
|