Module: Chef::Mixin::Properties
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#copy_properties_from(other, *includes, exclude: [ :name ]) ⇒ Object
Copy properties from another property object (resource).
-
#property_description(name) ⇒ String
The description of the property.
-
#property_is_set?(name) ⇒ Boolean
Whether this property has been set (or whether it has a default that has been retrieved).
-
#reset_property(name) ⇒ Object
Clear this property as if it had never been set.
Methods included from ParamsValidate
#lazy, #set_or_return, #validate
Class Method Details
.included(other) ⇒ Object
290 291 292 |
# File 'lib/chef/mixin/properties.rb', line 290 def self.included(other) other.extend ClassMethods end |
Instance Method Details
#copy_properties_from(other, *includes, exclude: [ :name ]) ⇒ Object
Copy properties from another property object (resource)
By default this copies all properties other than the name property (that is required to create the destination object so it has already been done in advance and this way we do not clobber the name that was set in that constructor). By default it copies everything, optional arguments can be use to only select a subset. Or specific excludes can be set (and the default exclude on the name property can also be overridden). Exclude has priority over include, although the caller is likely better off doing the set arithmetic themselves for explicitness.
“‘ruby action :doit do
# use it inside a block
file "/etc/whatever.xyz" do
copy_properties_from new_resource
end
# or directly call it
r = declare_resource(:file, "etc/whatever.xyz")
r.copy_properties_from(new_resource, :owner, :group, :mode)
end “‘
363 364 365 366 367 368 369 370 |
# File 'lib/chef/mixin/properties.rb', line 363 def copy_properties_from(other, *includes, exclude: [ :name ]) includes = other.class.properties.keys if includes.empty? includes -= exclude includes.each do |p| send(p, other.send(p)) if other.property_is_set?(p) end self end |
#property_description(name) ⇒ String
The description of the property
329 330 331 332 333 334 |
# File 'lib/chef/mixin/properties.rb', line 329 def property_description(name) property = self.class.properties[name.to_sym] raise ArgumentError, "Property #{name} is not defined in class #{self}" unless property property.description end |
#property_is_set?(name) ⇒ Boolean
Whether this property has been set (or whether it has a default that has been retrieved).
303 304 305 306 307 308 |
# File 'lib/chef/mixin/properties.rb', line 303 def property_is_set?(name) property = self.class.properties[name.to_sym] raise ArgumentError, "Property #{name} is not defined in class #{self}" unless property property.is_set?(self) end |
#reset_property(name) ⇒ Object
Clear this property as if it had never been set. It will thereafter return the default. been retrieved).
317 318 319 320 321 322 |
# File 'lib/chef/mixin/properties.rb', line 317 def reset_property(name) property = self.class.properties[name.to_sym] raise ArgumentError, "Property #{name} is not defined in class #{self}" unless property property.reset(self) end |