diff options
author | Seth Vargo <sethvargo@gmail.com> | 2014-06-26 12:32:11 -0700 |
---|---|---|
committer | Seth Vargo <sethvargo@gmail.com> | 2014-07-11 14:55:59 -0400 |
commit | 9a474f1c670fd68b757aa9d62378875c6c1f7abc (patch) | |
tree | 6da2fc812eee846e2bd6a5c57a359b40fb53f40f /lib | |
parent | fc8f9ef17261a05ba8cd3b882711c91676988123 (diff) | |
download | chef-9a474f1c670fd68b757aa9d62378875c6c1f7abc.tar.gz |
Allow default values to be a DelayedEvaluator
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 7 | ||||
-rw-r--r-- | lib/chef/resource/lwrp_base.rb | 4 |
2 files changed, 11 insertions, 0 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index a9799f749c..bedc67f357 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -95,6 +95,13 @@ class Chef val = arg else val = validate({ symbol => arg }, { symbol => validation })[symbol] + + # Handle the case where the "default" was a DelayedEvaluator. In + # this case, the block yields an optional parameter of +self+, + # which is the equivalent of "new_resource" + if val.is_a?(DelayedEvaluator) + val = val.call(self) + end end self.instance_variable_set(iv_symbol, val) end diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb index e91516e6f6..7b4e8bf4f1 100644 --- a/lib/chef/resource/lwrp_base.rb +++ b/lib/chef/resource/lwrp_base.rb @@ -119,6 +119,10 @@ class Chef run_context.node end + def self.lazy(&block) + DelayedEvaluator.new(&block) + end + # Default initializer. Sets the default action and allowed actions. def initialize(name, run_context=nil) super(name, run_context) |