module Poise::Helpers::Subresources::DefaultContainers
Helpers
to track default container resources. This is used to find a default parent for a child with no parent set. It flat out violates encapsulation to allow for the use of default parents to act as system-level defaults even when created in a nested scope.
@api private @since 2.0.0
Constants
- CONTAINER_MUTEX
Mutex to sync access to the containers array.
@see .containers
Public Class Methods
Find a default container for a resource class.
@param klass [Class] Resource
class to search for. @param run_context [Chef::RunContext] Context of the current run. @return [Chef::Resource]
# File lib/poise/helpers/subresources/default_containers.rb, line 50 def self.find(klass, run_context, self_resource: nil) CONTAINER_MUTEX.synchronize do containers(run_context).reverse_each do |resource| return resource if resource.is_a?(klass) && (!self_resource || self_resource != resource) end # Nothing found. nil end end
Add a resource to the array of default containers.
@param resource [Chef::Resource] Resource
to add. @param run_context [Chef::RunContext] Context of the current run. @return [void]
# File lib/poise/helpers/subresources/default_containers.rb, line 39 def self.register!(resource, run_context) CONTAINER_MUTEX.synchronize do containers(run_context) << resource end end
Private Class Methods
Get the array of all default container resources.
@note MUST BE CALLED FROM A LOCKED CONTEXT! @param run_context [Chef::RunContext] Context of the current run. @return [Array<Chef::Resource>]
# File lib/poise/helpers/subresources/default_containers.rb, line 67 def self.containers(run_context) # For test cases where nil gets used sometimes. return [] unless run_context && run_context.node && run_context.node.run_state run_context.node.run_state[:poise_default_containers] ||= [] end