summaryrefslogtreecommitdiff
path: root/lib/chef/resource_resolver.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-06-05 10:48:29 -0700
committerJohn Keiser <john@johnkeiser.com>2015-06-08 09:01:54 -0700
commit8f17f5223727cb9bec3c44b66a3fbe327b7a2f19 (patch)
tree05cebef51365af906081bc1430c6c15d048a7b40 /lib/chef/resource_resolver.rb
parent8d4e9d44995d6f7de5a0b681616ed8241e39ece3 (diff)
downloadchef-8f17f5223727cb9bec3c44b66a3fbe327b7a2f19.tar.gz
Make use_automatic_resource_name automatic
Diffstat (limited to 'lib/chef/resource_resolver.rb')
-rw-r--r--lib/chef/resource_resolver.rb49
1 files changed, 22 insertions, 27 deletions
diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb
index 1eb5e6d840..12618d693b 100644
--- a/lib/chef/resource_resolver.rb
+++ b/lib/chef/resource_resolver.rb
@@ -26,35 +26,15 @@ class Chef
attr_reader :node
attr_reader :resource
attr_reader :action
+ attr_reader :canonical
- def initialize(node, resource)
+ def initialize(node, resource, canonical: nil)
@node = node
@resource = resource.to_sym
+ @canonical = canonical
end
def resolve
- maybe_dynamic_resource_resolution ||
- maybe_chef_platform_lookup
- end
-
- def provided_by?(resource_class)
- !prioritized_handlers.include?(resource_class)
- end
-
- #
- # Resolve a resource by name.
- #
- # @param resource_name [Symbol] The resource DSL name (e.g. `:file`)
- # @param node [Chef::Node] The node on which the resource will run.
- #
- def self.resolve(resource_name, node: Chef.node)
- new(node, resource_name).resolve
- end
-
- protected
-
- # try dynamically finding a resource based on querying the resources to see what they support
- def maybe_dynamic_resource_resolution
# log this so we know what resources will work for the generic resource on the node (early cut)
Chef::Log.debug "Resources for generic #{resource} resource enabled on node include: #{enabled_handlers}"
@@ -69,17 +49,32 @@ class Chef
handler
end
- # try the old static lookup of resources by mangling name to resource klass
- def maybe_chef_platform_lookup
- Chef::Resource.resource_matching_short_name(resource)
+ def provided_by?(resource_class)
+ !prioritized_handlers.include?(resource_class)
end
+ #
+ # Resolve a resource by name.
+ #
+ # @param resource_name [Symbol] The resource DSL name (e.g. `:file`)
+ # @param node [Chef::Node] The node on which the resource will run. If not
+ # passed, will return the first match.
+ # @param canonical [Boolean] Whether to restrict the search to the canonical
+ # name (the one set by `resource_name`)
+ #
+ def self.resolve(resource_name, node: Chef.node, canonical: false)
+ new(node, resource_name, canonical: canonical).resolve
+ end
+
+ protected
+
def priority_map
Chef::Platform::ResourcePriorityMap.instance
end
def prioritized_handlers
- @prioritized_handlers ||= priority_map.list_handlers(node, resource)
+ @prioritized_handlers ||=
+ priority_map.list_handlers(node, resource, canonical: nil)
end
module Deprecated