Skip to content

Commit

Permalink
Revert "Merge pull request chef#2956 from chef/lcg/deploy-fixes"
Browse files Browse the repository at this point in the history
This reverts commit 2603e21, reversing
changes made to a7f5c92.

Conflicts:
	CHANGELOG.md
  • Loading branch information
jaym committed Mar 25, 2015
1 parent b6eb10f commit be67482
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 206 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

9 changes: 0 additions & 9 deletions lib/chef/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -996,15 +996,6 @@ def defined_at
end
end

#
# DSL method used to define attribute on a resource wrapping params_validate
#
def self.attribute(attr_name, validation_opts={})
define_method(attr_name) do |arg=NULL_ARG|
nillable_set_or_return(attr_name.to_sym, arg, validation_opts)
end
end

#
# The cookbook in which this Resource was defined (if any).
#
Expand Down
Loading

0 comments on commit be67482

Please sign in to comment.