Skip to content

Commit

Permalink
Merge pull request chef#3147 from chef/jdm/reverts
Browse files Browse the repository at this point in the history
Revert nillable resource attributes
  • Loading branch information
jaym committed Mar 25, 2015
2 parents b6eb10f + 5e0b48f commit 5d666b7
Show file tree
Hide file tree
Showing 11 changed files with 393 additions and 352 deletions.
3 changes: 0 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
## Unreleased

* Update policyfile API usage to match forthcoming Chef Server release
* make deploy resource attributes nillable (`symlink_before_migrate nil`) works now
* mixin the LWRP attribute DSL method into Chef::Resource directly
* make all LWRP attributes nillable
* `knife ssh` now has an --exit-on-error option that allows users to
fail-fast rather than moving on to the next machine.
* migrate macosx, windows, openbsd, and netbsd resources to dynamic resolution
Expand Down
61 changes: 19 additions & 42 deletions lib/chef/mixin/params_validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,58 +81,34 @@ def lazy(&block)
DelayedEvaluator.new(&block)
end

NULL_ARG = Object.new

def nillable_set_or_return(symbol, arg, validation)
def set_or_return(symbol, arg, validation)
iv_symbol = "@#{symbol.to_s}".to_sym
if NULL_ARG.equal?(arg)
if self.instance_variable_defined?(iv_symbol) == true
get_ivar(iv_symbol, symbol, validation)
if arg == nil && self.instance_variable_defined?(iv_symbol) == true
ivar = self.instance_variable_get(iv_symbol)
if(ivar.is_a?(DelayedEvaluator))
validate({ symbol => ivar.call }, { symbol => validation })[symbol]
else
# on access we create the iv and set it to nil for back-compat
set_ivar(iv_symbol, symbol, nil, validation)
ivar
end
else
set_ivar(iv_symbol, symbol, arg, validation)
end
end
if(arg.is_a?(DelayedEvaluator))
val = arg
else
val = validate({ symbol => arg }, { symbol => validation })[symbol]

def set_or_return(symbol, arg, validation)
iv_symbol = "@#{symbol.to_s}".to_sym
if arg == nil && self.instance_variable_defined?(iv_symbol) == true
get_ivar(iv_symbol, symbol, validation)
else
set_ivar(iv_symbol, symbol, arg, validation)
# 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
end

private

def get_ivar(iv_symbol, symbol, validation)
ivar = self.instance_variable_get(iv_symbol)
if(ivar.is_a?(DelayedEvaluator))
validate({ symbol => ivar.call }, { symbol => validation })[symbol]
else
ivar
end
end

def set_ivar(iv_symbol, symbol, arg, validation)
if(arg.is_a?(DelayedEvaluator))
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

# Return the value of a parameter, or nil if it doesn't exist.
def _pv_opts_lookup(opts, key)
if opts.has_key?(key.to_s)
Expand Down Expand Up @@ -263,3 +239,4 @@ def _pv_name_attribute(opts, key, is_name_attribute=true)
end
end
end

Loading

0 comments on commit 5d666b7

Please sign in to comment.