Method: Chef::Mixin::Properties::ClassMethods#state_properties
- Defined in:
- lib/chef/mixin/properties.rb
#state_properties(*names) ⇒ Array<Property>
Get or set the list of desired state properties for this resource.
State properties are properties that describe the desired state of the system, such as file permissions or ownership. In general, state properties are properties that could be populated by examining the state of the system (e.g., File.stat can tell you the permissions on an existing file). Contrarily, properties that are not “state properties” usually modify the way Chef itself behaves, for example by providing additional options for a package manager to use when installing a package.
This method is unnecessary when declaring properties with property; properties are added to state_properties by default, and can be turned off with ‘desired_state: false`.
“‘ruby property :x # part of desired state property :y, desired_state: false # not part of desired state “`
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/chef/mixin/properties.rb', line 195 def state_properties(*names) unless names.empty? names = names.map(&:to_sym).uniq local_properties = properties(false) # Add new properties to the list. names.each do |name| property = properties[name] if !property self.property name, instance_variable_name: false, desired_state: true elsif !property.desired_state? self.property name, desired_state: true end end # If state_attrs *excludes* something which is currently desired state, # mark it as desired_state: false. local_properties.each do |name, property| if property.desired_state? && !names.include?(name) self.property name, desired_state: false end end end properties.values.select(&:desired_state?) end |