class Chef::ResourceResolver
Attributes
@api private
@api private
@api private
@api private
Public Class Methods
Whether the given handler attempts to provide the resource class at all.
@api private
# File lib/chef/resource_resolver.rb, line 114 def self.includes_handler?(resource_name, resource_class) handler_map.list(nil, resource_name).include?(resource_class) end
Resolve a list of all resources that implement the given DSL
(in order of preference).
@param resource_name
[Symbol] The resource DSL
name (e.g. `:file`). @param node [Chef::Node] The node against which to resolve. `nil` causes
platform filters to be ignored.
@param canonical [Boolean] `true` or `false` to match canonical or
non-canonical values only. `nil` to ignore canonicality.
# File lib/chef/resource_resolver.rb, line 46 def self.list(resource_name, node: nil, canonical: nil) new(node, resource_name, canonical: canonical).list end
Create a resolver.
@param node [Chef::Node] The node against which to resolve. `nil` causes
platform filters to be ignored.
@param resource_name
[Symbol] The resource DSL
name (e.g. `:file`). @param canonical [Boolean] `true` or `false` to match canonical or
non-canonical values only. `nil` to ignore canonicality. Default: `nil`
@api private use Chef::ResourceResolver.resolve
or .list instead.
# File lib/chef/resource_resolver.rb, line 71 def initialize(node, resource_name, canonical: nil) @node = node @resource_name = resource_name.to_sym @canonical = canonical end
Resolve a resource by name.
@param resource_name
[Symbol] The resource DSL
name (e.g. `:file`). @param node [Chef::Node] The node against which to resolve. `nil` causes
platform filters to be ignored.
# File lib/chef/resource_resolver.rb, line 32 def self.resolve(resource_name, node: nil, canonical: nil) new(node, resource_name, canonical: canonical).resolve end
Protected Class Methods
# File lib/chef/resource_resolver.rb, line 124 def self.handler_map Chef.resource_handler_map end
# File lib/chef/resource_resolver.rb, line 120 def self.priority_map Chef.resource_priority_map end
Public Instance Methods
@api private
# File lib/chef/resource_resolver.rb, line 94 def list Chef::Log.trace "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" prioritized_handlers end
Whether this DSL
is provided by the given resource_class.
Does NOT call provides? on the resource (it is assumed this is being called from provides?).
@api private
# File lib/chef/resource_resolver.rb, line 106 def provided_by?(resource_class) potential_handlers.include?(resource_class) end
@api private use Chef::ResourceResolver.resolve
instead.
# File lib/chef/resource_resolver.rb, line 78 def resolve # log this so we know what resources will work for the generic resource on the node (early cut) Chef::Log.trace "Resources for generic #{resource_name} resource enabled on node include: #{prioritized_handlers}" handler = prioritized_handlers.first if handler Chef::Log.trace "Resource for #{resource_name} is #{handler}" else Chef::Log.trace "Dynamic resource resolver FAILED to resolve a resource for #{resource_name}" end handler end
Protected Instance Methods
# File lib/chef/resource_resolver.rb, line 141 def enabled_handlers potential_handlers.select { |handler| !overrode_provides?(handler) || handler.provides?(node, resource_name) } end
# File lib/chef/resource_resolver.rb, line 132 def handler_map Chef.resource_handler_map end
# File lib/chef/resource_resolver.rb, line 156 def overrode_provides?(handler) handler.method(:provides?).owner != Chef::Resource.method(:provides?).owner end
@api private
# File lib/chef/resource_resolver.rb, line 137 def potential_handlers handler_map.list(node, resource_name, canonical: canonical).uniq end
# File lib/chef/resource_resolver.rb, line 145 def prioritized_handlers @prioritized_handlers ||= begin enabled_handlers = self.enabled_handlers prioritized = priority_map.list(node, resource_name, canonical: canonical).flatten(1) prioritized &= enabled_handlers # Filter the priority map by the actual enabled handlers prioritized |= enabled_handlers # Bring back any handlers that aren't in the priority map, at the *end* (ordered set) prioritized end end
# File lib/chef/resource_resolver.rb, line 128 def priority_map Chef.resource_priority_map end