Method: Chef::Mixin::Properties::ClassMethods#identity_properties
- Defined in:
- lib/chef/mixin/properties.rb
#identity_properties(*names) ⇒ Array<Property>
Set the identity of this resource to a particular set of properties.
This drives #identity, which returns data that uniquely refers to a given resource on the given node (in such a way that it can be correlated across Chef runs).
This method is unnecessary when declaring properties with property; properties can be added to identity during declaration with ‘identity: true`.
“‘ruby property :x, identity: true # part of identity property :y # not part of identity “`
If no properties are marked as identity, “name” is considered the identity.
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/chef/mixin/properties.rb', line 244 def identity_properties(*names) unless names.empty? names = names.map(&:to_sym) # Add or change properties that are not part of the identity. names.each do |name| property = properties[name] if !property self.property name, instance_variable_name: false, identity: true elsif !property.identity? self.property name, identity: true end end # If identity_properties *excludes* something which is currently part of # the identity, mark it as identity: false. properties.each do |name, property| if property.identity? && !names.include?(name) self.property name, identity: false end end end result = properties.values.select(&:identity?) # if there are no other identity properties set, then the name_property becomes the identity, or # failing that we use the actual name. if result.empty? result = name_property ? [ properties[name_property] ] : [ properties[:name] ] end result end |