diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-04 10:59:25 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-23 15:23:02 -0700 |
commit | 8b17c3315fe692fa075db410f9ba977557304907 (patch) | |
tree | 5adfa7584209a8401c8b6ee449b7a875d071ddc5 /lib/chef | |
parent | 9916aee174a54c58d00fbea35c0e2c01ac77fef1 (diff) | |
download | chef-8b17c3315fe692fa075db410f9ba977557304907.tar.gz |
Evaluate lazy defaults in context of the instance
Diffstat (limited to 'lib/chef')
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 926387b888..c920bdc992 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -94,7 +94,9 @@ class Chef if self.instance_variable_defined?(iv_symbol) value = self.instance_variable_get(iv_symbol) if value.is_a?(DelayedEvaluator) - value = validate({ symbol => value.call }, { symbol => validation })[symbol] + # Pass optional first parameter of self + value = value.call(self) + value = validate({ symbol => value }, { symbol => validation })[symbol] end # Get the default value @@ -107,7 +109,11 @@ class Chef # this case, the block yields an optional parameter of +self+, # which is the equivalent of "new_resource" if value.is_a?(DelayedEvaluator) - value = value.call(self) + if value.arity >= 1 + value = value.call(self) + else + value = instance_eval(&value) + end end # Defaults are presently "stickily" set on the instance @@ -281,7 +287,7 @@ class Chef if opts.has_key?(key.to_s) opts[key.to_s] = instance_exec(opts[key], &coercer) elsif opts.has_key?(key.to_sym) - opts[key.to_sym] = instance_exec(opts[key], &coercer) + opts[key.to_sym] = instance_exec(opts[key], &coercer) end end end |