summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel DeLeo <dan@opscode.com>2010-06-29 16:38:10 -0700
committerDaniel DeLeo <dan@opscode.com>2010-06-29 16:38:10 -0700
commitf7ffb400270b2bda02ec352fb449c038f2399637 (patch)
tree1c95a958586677059e30bd5b0f949f7f3ce3a79d
parenta6c2983d77025a3e9091f5db565d23a12a65463b (diff)
downloadchef-f7ffb400270b2bda02ec352fb449c038f2399637.tar.gz
[CHEF-1400] support deprecated @node usage in resources
-rw-r--r--chef/lib/chef/resource.rb14
-rw-r--r--chef/spec/unit/resource_spec.rb4
2 files changed, 14 insertions, 4 deletions
diff --git a/chef/lib/chef/resource.rb b/chef/lib/chef/resource.rb
index fe1c734d49..459317d187 100644
--- a/chef/lib/chef/resource.rb
+++ b/chef/lib/chef/resource.rb
@@ -24,14 +24,17 @@ require 'chef/mixin/convert_to_class_name'
require 'chef/resource_collection'
require 'chef/node'
+require 'chef/mixin/deprecation'
+
class Chef
class Resource
HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name]
-
+
include Chef::Mixin::CheckHelper
include Chef::Mixin::ParamsValidate
include Chef::Mixin::Language
include Chef::Mixin::ConvertToClassName
+ include Chef::Mixin::Deprecation
attr_accessor :params, :provider, :updated, :allowed_actions, :run_context, :cookbook_name, :recipe_name, :enclosing_provider
attr_accessor :source_line
@@ -60,6 +63,8 @@ class Chef
@notifies_immediate = Array.new
@notifies_delayed = Array.new
@source_line = nil
+
+ @node = run_context ? deprecated_ivar(run_context.node, :node, :warn) : nil
end
def node
@@ -237,9 +242,10 @@ class Chef
def to_hash
instance_vars = Hash.new
self.instance_variables.each do |iv|
- iv = iv.to_s
- next if iv == "@run_context"
- instance_vars[iv.sub(/^@/,'').to_sym] = self.instance_variable_get(iv)
+ #iv = iv.to_s
+ #next if iv == "@run_context"
+ key = iv.to_s.sub(/^@/,'').to_sym
+ instance_vars[key] = self.instance_variable_get(iv) unless (key == :run_context) || (key == :node)
end
instance_vars
end
diff --git a/chef/spec/unit/resource_spec.rb b/chef/spec/unit/resource_spec.rb
index daf6508a3f..6df4f6cfd1 100644
--- a/chef/spec/unit/resource_spec.rb
+++ b/chef/spec/unit/resource_spec.rb
@@ -232,6 +232,10 @@ describe Chef::Resource do
end
+ it "supports accessing the node via the @node instance variable [DEPRECATED]" do
+ @resource.instance_variable_get(:@node).should == @node
+ end
+
it "runs an action by finding its provider, loading the current resource and then running the action" do
pending
end