summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAdam Edwards <adamed@opscode.com>2014-03-27 05:28:38 -0700
committerAdam Edwards <adamed@opscode.com>2014-03-29 00:21:04 -0700
commit8fef6af58a397d79de6e46642e2480f83ae77628 (patch)
tree8a18b652e239115b186fb445b42aeceab7f7ac00 /lib
parentfe1279f3bbabba5add37a490f3c9e098a76ed896 (diff)
downloadchef-8fef6af58a397d79de6e46642e2480f83ae77628.tar.gz
Guard resource new specs and spec fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/resource.rb1
-rw-r--r--lib/chef/resource/conditional/guard_interpreter.rb15
-rw-r--r--lib/chef/resource/execute.rb6
-rw-r--r--lib/chef/resource/powershell_script.rb2
-rw-r--r--lib/chef/resource/script.rb13
5 files changed, 25 insertions, 12 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 5db03ccf02..4a182c28ab 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -226,7 +226,6 @@ F
attr_reader :resource_name
attr_reader :not_if_args
attr_reader :only_if_args
- attr_reader :guard_inherited_attributes
attr_reader :elapsed_time
diff --git a/lib/chef/resource/conditional/guard_interpreter.rb b/lib/chef/resource/conditional/guard_interpreter.rb
index a174037587..0165b51aae 100644
--- a/lib/chef/resource/conditional/guard_interpreter.rb
+++ b/lib/chef/resource/conditional/guard_interpreter.rb
@@ -30,7 +30,12 @@ class Chef
empty_events = Chef::EventDispatch::Dispatcher.new
anonymous_run_context = Chef::RunContext.new(parent_resource.node, {}, empty_events)
- @resource = resource_class.new('anonymous', anonymous_run_context)
+ @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
+
@handled_exceptions = handled_exceptions ? handled_exceptions : []
merge_inherited_attributes(parent_resource)
@source_line = source_line if source_line
@@ -62,7 +67,7 @@ class Chef
def get_resource_class(parent_resource, resource_symbol)
if parent_resource.nil? || parent_resource.node.nil?
- raise ArgumentError, "Node for anonymous resource must not be nil"
+ raise ArgumentError, "Node for guard resource parent must not be nil"
end
Chef::Resource.resource_for_node(resource_symbol, parent_resource.node)
end
@@ -76,7 +81,11 @@ class Chef
end
def merge_inherited_attributes(parent_resource)
- inherited_attributes = parent_resource.guard_inherited_attributes
+ inherited_attributes = []
+
+ if parent_resource.respond_to?(:guard_inherited_attributes)
+ inherited_attributes = parent_resource.send(:guard_inherited_attributes)
+ end
if inherited_attributes
inherited_attributes.each do |attribute|
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index c51e534dec..7c4fa48c0a 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -125,12 +125,6 @@ class Chef
)
end
- protected
-
- def append_guard_inherited_attributes(inherited_attributes)
- @guard_inherited_attributes.concat(inherited_attributes)
- end
-
end
end
end
diff --git a/lib/chef/resource/powershell_script.rb b/lib/chef/resource/powershell_script.rb
index c2bb28c3e2..87cb225f73 100644
--- a/lib/chef/resource/powershell_script.rb
+++ b/lib/chef/resource/powershell_script.rb
@@ -23,7 +23,7 @@ class Chef
def initialize(name, run_context=nil)
super(name, run_context, :powershell_script, "powershell.exe")
- append_guard_inherited_attributes([:architecture])
+ set_guard_inherited_attributes([:architecture])
@convert_boolean_return = nil
end
diff --git a/lib/chef/resource/script.rb b/lib/chef/resource/script.rb
index 7d56d1d0c6..5619d4e9aa 100644
--- a/lib/chef/resource/script.rb
+++ b/lib/chef/resource/script.rb
@@ -33,7 +33,8 @@ class Chef
@interpreter = nil
@flags = nil
@guard_inherited_attributes = []
- append_guard_inherited_attributes(
+
+ set_guard_inherited_attributes(
[
:cwd,
:environment,
@@ -68,6 +69,16 @@ class Chef
)
end
+ protected
+
+ def set_guard_inherited_attributes(inherited_attributes)
+ @guard_inherited_attributes.concat(inherited_attributes).uniq
+ end
+
+ def guard_inherited_attributes
+ @guard_inherited_attributes
+ end
+
end
end
end