diff options
author | Adam Edwards <adamed@opscode.com> | 2014-03-29 08:43:05 -0700 |
---|---|---|
committer | Adam Edwards <adamed@opscode.com> | 2014-03-29 08:43:05 -0700 |
commit | 7d4f5e04ce9851dce6f97c72ffee8b2cca2b58bc (patch) | |
tree | 3c58f38d684afa1a183ed3920c54e374383d2201 /lib/chef/guard_interpreter | |
parent | f596b16abda4aa0642add2dd2f0af900956f6a73 (diff) | |
download | chef-7d4f5e04ce9851dce6f97c72ffee8b2cca2b58bc.tar.gz |
CR feedback: centralize resource guard evaluation logic to increase readability
Diffstat (limited to 'lib/chef/guard_interpreter')
-rw-r--r-- | lib/chef/guard_interpreter/resource_guard_interpreter.rb | 33 |
1 files changed, 18 insertions, 15 deletions
diff --git a/lib/chef/guard_interpreter/resource_guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb index c2a2b1d6b4..fc1d4a1df8 100644 --- a/lib/chef/guard_interpreter/resource_guard_interpreter.rb +++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb @@ -25,19 +25,7 @@ class Chef def initialize(parent_resource, command, opts, &block) super(command, opts) @parent_resource = parent_resource - - resource_class = get_resource_class(parent_resource) - - raise ArgumentError, "Specified guard_interpreter resource #{parent_resource.guard_interpreter.to_s} unknown for this platform" if resource_class.nil? - - empty_events = Chef::EventDispatch::Dispatcher.new - anonymous_run_context = Chef::RunContext.new(parent_resource.node, {}, empty_events) - - @resource = resource_class.new('Guard resource', anonymous_run_context) - - if ! @resource.kind_of?(Chef::Resource::Script) - raise ArgumentError, "Specified guard interpreter class #{resource_class} must be a kind of Chef::Resource::Script resource" - end + @resource = get_interpreter_resource(parent_resource) end def evaluate @@ -80,11 +68,26 @@ class Chef resource_updated end - def get_resource_class(parent_resource) + def get_interpreter_resource(parent_resource) if parent_resource.nil? || parent_resource.node.nil? raise ArgumentError, "Node for guard resource parent must not be nil" end - Chef::Resource.resource_for_node(parent_resource.guard_interpreter, parent_resource.node) + + resource_class = Chef::Resource.resource_for_node(parent_resource.guard_interpreter, parent_resource.node) + + if resource_class.nil? + raise ArgumentError, "Specified guard_interpreter resource #{parent_resource.guard_interpreter.to_s} unknown for this platform" + end + + empty_events = Chef::EventDispatch::Dispatcher.new + anonymous_run_context = Chef::RunContext.new(parent_resource.node, {}, empty_events) + interpreter_resource = resource_class.new('Guard resource', anonymous_run_context) + + if ! interpreter_resource.kind_of?(Chef::Resource::Script) + raise ArgumentError, "Specified guard interpreter class #{resource_class} must be a kind of Chef::Resource::Script resource" + end + + interpreter_resource end def block_from_attributes(attributes) |