summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-05-13 13:38:41 -0700
committerJohn Keiser <john@johnkeiser.com>2015-05-13 13:43:15 -0700
commit34638bf82798bdcf01c28fbde6ac68dd1949c301 (patch)
treeba58fa54264d520f6d4b9ae201176f5727e462ad
parentb6336c9de74095cc087463d5c6a3b28aac44e688 (diff)
downloadchef-34638bf82798bdcf01c28fbde6ac68dd1949c301.tar.gz
Add Chef::ResourceResolver.resolvejk/missing_method_missing
-rw-r--r--DOC_CHANGES.md2
-rw-r--r--external_tests/foodcritic.gemfile1
-rw-r--r--lib/chef/resource_resolver.rb10
-rw-r--r--spec/unit/lwrp_spec.rb4
4 files changed, 16 insertions, 1 deletions
diff --git a/DOC_CHANGES.md b/DOC_CHANGES.md
index 31ea79f3d9..b0a8e0aaaf 100644
--- a/DOC_CHANGES.md
+++ b/DOC_CHANGES.md
@@ -27,7 +27,7 @@ Users are encouraged to declare resources in their own namespaces instead of put
Starting with Chef 12.4.0, accessing an LWRP class by name from the `Chef::Resource` namespace will trigger a deprecation warning message. This means that if your cookbook includes the LWRP `mycookbook/resources/myresource.rb`, you will no longer be able to extend or reference `Chef::Resource::MycookbookMyresource` in Ruby code. LWRP recipe DSL does not change: the LWRP will still be available to recipes as `mycookbook_myresource`.
-You can still get the LWRP class by calling `Chef::Resource.resource_matching_short_name(:mycookbook_myresource)`.
+You can still get the LWRP class by calling `Chef::ResourceResolver.resolve(:mycookbook_myresource)`.
The primary aim here is clearing out the `Chef::Resource` namespace.
diff --git a/external_tests/foodcritic.gemfile b/external_tests/foodcritic.gemfile
index 7d2261eff3..a2b71a0d8c 100644
--- a/external_tests/foodcritic.gemfile
+++ b/external_tests/foodcritic.gemfile
@@ -6,3 +6,4 @@ gem 'foodcritic', github: 'acrmp/foodcritic'
gem 'cucumber'
gem 'rubocop'
gem 'simplecov'
+gem 'minitest'
diff --git a/lib/chef/resource_resolver.rb b/lib/chef/resource_resolver.rb
index d4151e7125..a987b236c2 100644
--- a/lib/chef/resource_resolver.rb
+++ b/lib/chef/resource_resolver.rb
@@ -51,6 +51,16 @@ class Chef
end.sort {|a,b| a.to_s <=> b.to_s }
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
+
private
# try dynamically finding a resource based on querying the resources to see what they support
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index a1cccb3071..ff7f8e7d7b 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -164,6 +164,10 @@ describe "LWRP" do
expect { Chef::Resource::LwrpFoo }.to raise_error(Chef::Exceptions::DeprecatedFeatureError)
end
+ it "should be resolvable with Chef::ResourceResolver.resolve(:lwrp_foo)" do
+ expect(Chef::ResourceResolver.resolve(:lwrp_foo, node: Chef::Node.new)).to eq(get_lwrp(:lwrp_foo))
+ end
+
it "should set resource_name" do
expect(get_lwrp(:lwrp_foo).new("blah").resource_name).to eql(:lwrp_foo)
end