diff options
author | Adam Edwards <adamed@opscode.com> | 2014-03-28 14:08:27 -0700 |
---|---|---|
committer | Adam Edwards <adamed@opscode.com> | 2014-03-29 00:21:12 -0700 |
commit | dfe1ebf9bf59d02aa78c1fdef8787af1665a22fd (patch) | |
tree | 3df2b552435c442bf5f1e9b4d4562e969dc31998 /lib | |
parent | e0b02d69aaf9f408cfd9dbe9ea47561f694815bf (diff) | |
download | chef-dfe1ebf9bf59d02aa78c1fdef8787af1665a22fd.tar.gz |
Fix namespacing issues caused by moving guard_interpreter logic out of Chef::Resource
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/guard_interpreter/default_guard_interpreter.rb (renamed from lib/chef/resource/conditional/default_guard_interpreter.rb) | 20 | ||||
-rw-r--r-- | lib/chef/guard_interpreter/resource_guard_interpreter.rb (renamed from lib/chef/resource/conditional/guard_interpreter.rb) | 20 | ||||
-rw-r--r-- | lib/chef/resource.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource/conditional.rb | 18 |
4 files changed, 33 insertions, 27 deletions
diff --git a/lib/chef/resource/conditional/default_guard_interpreter.rb b/lib/chef/guard_interpreter/default_guard_interpreter.rb index 198db6a7aa..f7d039c1cf 100644 --- a/lib/chef/resource/conditional/default_guard_interpreter.rb +++ b/lib/chef/guard_interpreter/default_guard_interpreter.rb @@ -17,18 +17,20 @@ # class Chef - class DefaultGuardInterpreter + class GuardInterpreter + class DefaultGuardInterpreter - protected - def initialize - end + protected + + def initialize + end + + public - public - - def translate_command_block(command, opts, &block) - [command, block] + def translate_command_block(command, opts, &block) + [command, block] + end end - end end diff --git a/lib/chef/resource/conditional/guard_interpreter.rb b/lib/chef/guard_interpreter/resource_guard_interpreter.rb index 4f2fefb3cc..946ee2ba49 100644 --- a/lib/chef/resource/conditional/guard_interpreter.rb +++ b/lib/chef/guard_interpreter/resource_guard_interpreter.rb @@ -16,18 +16,11 @@ # limitations under the License. # -require 'chef/resource/conditional/default_guard_interpreter' +require 'chef/guard_interpreter/default_guard_interpreter' class Chef - class GuardInterpreter < DefaultGuardInterpreter - - def self.translate_command_block(parent_resource, command, opts, &block) - evaluator = parent_resource.guard_interpreter == :default ? - DefaultGuardInterpreter.new : - new(parent_resource.guard_interpreter, parent_resource) - - evaluator.translate_command_block(command, opts, &block) - end + class GuardInterpreter + class ResourceGuardInterpreter < DefaultGuardInterpreter def translate_command_block(command, opts, &block) merge_inherited_attributes @@ -40,8 +33,6 @@ class Chef end end - protected - def initialize(resource_symbol, parent_resource) @parent_resource = parent_resource @@ -59,6 +50,8 @@ class Chef end end + protected + def evaluate_action(action=nil, &block) @resource.instance_eval(&block) @@ -81,8 +74,6 @@ class Chef end end - private - def get_resource_class(parent_resource, resource_symbol) if parent_resource.nil? || parent_resource.node.nil? raise ArgumentError, "Node for guard resource parent must not be nil" @@ -118,4 +109,5 @@ class Chef end end end + end end diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 7c191b700e..7d96b26b4b 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -23,7 +23,7 @@ require 'chef/dsl/data_query' require 'chef/dsl/registry_helper' require 'chef/dsl/reboot_pending' require 'chef/mixin/convert_to_class_name' -require 'chef/resource/conditional/guard_interpreter' +require 'chef//guard_interpreter/resource_guard_interpreter' require 'chef/resource/conditional' require 'chef/resource/conditional_action_not_nothing' require 'chef/resource_collection' diff --git a/lib/chef/resource/conditional.rb b/lib/chef/resource/conditional.rb index 94c4fe03f4..19881feb70 100644 --- a/lib/chef/resource/conditional.rb +++ b/lib/chef/resource/conditional.rb @@ -17,7 +17,7 @@ # require 'chef/mixin/shell_out' -require 'chef/resource/conditional/guard_interpreter' +require 'chef/guard_interpreter/resource_guard_interpreter' class Chef class Resource @@ -31,12 +31,12 @@ class Chef end def self.not_if(parent_resource, command=nil, command_opts={}, &block) - translated_command, translated_block = Chef::GuardInterpreter.translate_command_block(parent_resource, command, command_opts, &block) + translated_command, translated_block = translate_command_block(parent_resource, command, command_opts, &block) new(:not_if, translated_command, command_opts, &translated_block) end def self.only_if(parent_resource, command=nil, command_opts={}, &block) - translated_command, translated_block = Chef::GuardInterpreter.translate_command_block(parent_resource, command, command_opts, &block) + translated_command, translated_block = translate_command_block(parent_resource, command, command_opts, &block) new(:only_if, translated_command, command_opts, &translated_block) end @@ -103,6 +103,18 @@ class Chef end end + def self.translate_command_block(parent_resource, command, opts, &block) + guard_interpreter = nil + + if parent_resource.guard_interpreter == :default + guard_interpreter = Chef::GuardInterpreter::DefaultGuardInterpreter.new + else + guard_interpreter = Chef::GuardInterpreter::ResourceGuardInterpreter.new(parent_resource.guard_interpreter, parent_resource) + end + + guard_interpreter.translate_command_block(command, opts, &block) + end + end end end |