diff options
author | Steven Danna <steve@opscode.com> | 2014-12-11 12:24:08 +0000 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2015-02-17 08:46:37 -0500 |
commit | b497289183b6696f5da838274e57c08fbd6c4872 (patch) | |
tree | cc72c0fd29911d24033b90fe7962e36092d8faae | |
parent | 55b6e39b2191de3a743abc229951e17373638eed (diff) | |
download | chef-b497289183b6696f5da838274e57c08fbd6c4872.tar.gz |
Use Chef::Mixin::DescendantsTracker to track registered verifications
-rw-r--r-- | lib/chef/resource/file/verification.rb | 17 | ||||
-rw-r--r-- | spec/unit/resource/file/verification_spec.rb | 4 |
2 files changed, 13 insertions, 8 deletions
diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index 5e75cbf6a7..a1dec3c17f 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -17,6 +17,7 @@ # require 'chef/exceptions' +require 'chef/mixin/descendants_tracker' class Chef class Resource @@ -48,7 +49,7 @@ class Chef # class Chef # class Resource # class File::Verification::Foo < Chef::Resource::File::Verification - # register :noop + # provides :noop # def verify(path, opts) # #yolo # true @@ -60,18 +61,22 @@ class Chef # class Verification - @@registered_verifications = {} + extend Chef::Mixin::DescendantsTracker - def self.register(name) - @@registered_verifications[name] = self.name + def self.provides(name) + @provides = name + end + + def self.provides?(name) + @provides == name end def self.lookup(name) - c = @@registered_verifications[name] + c = descendants.find {|d| d.provides?(name) } if c.nil? raise Chef::Exceptions::VerificationNotFound.new "No file verification for #{name} found." end - Object.const_get(c) + c end def initialize(parent_resource, command, opts, &block) diff --git a/spec/unit/resource/file/verification_spec.rb b/spec/unit/resource/file/verification_spec.rb index 6b807da45b..8e40a50cb8 100644 --- a/spec/unit/resource/file/verification_spec.rb +++ b/spec/unit/resource/file/verification_spec.rb @@ -27,7 +27,7 @@ describe Chef::Resource::File::Verification do describe "verification registration" do it "registers a verification for later use" do class Chef::Resource::File::Verification::Wombat < Chef::Resource::File::Verification - register :tabmow + provides :tabmow end expect(Chef::Resource::File::Verification.lookup(:tabmow)).to eq(Chef::Resource::File::Verification::Wombat) end @@ -89,7 +89,7 @@ describe Chef::Resource::File::Verification do context "with a named verification(Symbol)" do before(:each) do class Chef::Resource::File::Verification::Turtle < Chef::Resource::File::Verification - register :cats + provides :cats def verify(path, opts) end end |