module Chef::Mixin::Properties
Public Class Methods
# File lib/chef/mixin/properties.rb, line 290 def self.included(other) other.extend ClassMethods end
Public Instance Methods
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 “`
@param other [Object] the other object (Chef::Resource
) which implements the properties API @param includes [Array<Symbol>] splat-args list of symbols of the properties to copy. @param exclude [Array<Symbol>] list of symbols of the properties to exclude. @return the self object the properties were copied to for method chaining
# 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
The description of the property
@param name [Symbol] The name of the property. @return [String] The description of the property.
# 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
Whether this property has been set (or whether it has a default that has been retrieved).
@param name [Symbol] The name of the property. @return [Boolean] `true` if the property has been set.
# 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
Clear this property as if it had never been set. It will thereafter return the default. been retrieved).
@param name [Symbol] The name of the property.
# 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