summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2016-10-18 10:46:54 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2016-10-18 10:46:54 -0700
commitdffde98d6228ccb4ea1dbd19d4db08edc62625b8 (patch)
tree39b5e058f3b435256123f437d2c7a8b39de923b4 /lib
parent770ad9a6f575bf21d73c542756aeef311a2a8fbe (diff)
downloadchef-dffde98d6228ccb4ea1dbd19d4db08edc62625b8.tar.gz
remove dependency on Chef.run_context global state
introduce run_context.root_run_context that avoids global state Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/chef/dsl/declare_resource.rb2
-rw-r--r--lib/chef/run_context.rb13
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/chef/dsl/declare_resource.rb b/lib/chef/dsl/declare_resource.rb
index ed3083e1ca..2ebef98bd4 100644
--- a/lib/chef/dsl/declare_resource.rb
+++ b/lib/chef/dsl/declare_resource.rb
@@ -47,7 +47,7 @@ class Chef
when Chef::RunContext
rc
when :root
- Chef.run_context
+ run_context.root_run_context
when :parent
run_context.parent_run_context
else
diff --git a/lib/chef/run_context.rb b/lib/chef/run_context.rb
index 5d29f766c9..0ebf1b228d 100644
--- a/lib/chef/run_context.rb
+++ b/lib/chef/run_context.rb
@@ -85,6 +85,19 @@ class Chef
attr_reader :parent_run_context
#
+ # The root run context.
+ #
+ # @return [Chef::RunContext] The root run context.
+ #
+ def root_run_context
+ rc = self
+ until rc.parent_run_context.nil?
+ rc = rc.parent_run_context
+ end
+ rc
+ end
+
+ #
# The collection of resources intended to be converged (and able to be
# notified).
#