diff options
author | John Keiser <john@johnkeiser.com> | 2015-06-03 15:47:14 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-06-23 15:23:01 -0700 |
commit | 0a55c383bcd1f658f68c4ee1dbb2dd910cea052b (patch) | |
tree | a6e9c33ff083710f7ca4240224609ae4ce5072c6 | |
parent | 2278a61bc0fafe7fdd208c30b12cc11db9547d04 (diff) | |
download | chef-0a55c383bcd1f658f68c4ee1dbb2dd910cea052b.tar.gz |
Add name_property
-rw-r--r-- | lib/chef/mixin/params_validate.rb | 13 | ||||
-rw-r--r-- | spec/unit/property/validation_spec.rb | 2 | ||||
-rw-r--r-- | spec/unit/property_spec.rb | 5 |
3 files changed, 10 insertions, 10 deletions
diff --git a/lib/chef/mixin/params_validate.rb b/lib/chef/mixin/params_validate.rb index 6fe5036570..629243412d 100644 --- a/lib/chef/mixin/params_validate.rb +++ b/lib/chef/mixin/params_validate.rb @@ -83,7 +83,7 @@ class Chef def set_or_return(symbol, arg, validation) iv_symbol = "@#{symbol.to_s}".to_sym - if arg == nil && self.instance_variable_defined?(iv_symbol) == true + 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] @@ -196,7 +196,7 @@ class Chef # Assign a default value to a parameter. def _pv_default(opts, key, default_value) value = _pv_opts_lookup(opts, key) - if value == nil + if value.nil? opts[key] = default_value end end @@ -204,7 +204,7 @@ class Chef # Check a parameter against a regular expression. def _pv_regex(opts, key, regex) value = _pv_opts_lookup(opts, key) - if value != nil + if !value.nil? passes = false Array(regex).each do |r| if value != nil @@ -233,13 +233,14 @@ class Chef end # Allow a parameter to default to @name - def _pv_name_attribute(opts, key, is_name_attribute=true) - if is_name_attribute - if opts[key] == nil + def _pv_name_property(opts, key, is_name_property=true) + if is_name_property + if opts[key].nil? opts[key] = self.instance_variable_get("@name") end end end + alias :_pv_name_attribute :_pv_name_property # Compare the way "case" would (i.e. `===`) def _pv_is(opts, key, to_be) diff --git a/spec/unit/property/validation_spec.rb b/spec/unit/property/validation_spec.rb index 586d94ee18..60016ce2e1 100644 --- a/spec/unit/property/validation_spec.rb +++ b/spec/unit/property/validation_spec.rb @@ -407,7 +407,7 @@ describe "Chef::Resource.property validation" do end # with_property ':x, name_property: true, required: true' do - with_property ':x, required: true, name_attribute: true' do + with_property ':x, required: true, name_property: true' do it "if x is not specified, retrieval fails" do expect { resource.x }.to raise_error Chef::Exceptions::ValidationFailed end diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index 17857b8a57..5f88561f3a 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -750,8 +750,7 @@ describe "Chef::Resource.property" do end end - # [ 'name_attribute', 'name_property' ].each do |name| - name = 'name_attribute' + [ 'name_attribute', 'name_property' ].each do |name| context "Chef::Resource::PropertyType##{name}" do with_property ":x, #{name}: true" do it "defaults x to resource.name" do @@ -783,5 +782,5 @@ describe "Chef::Resource.property" do # end # end end - # end + end end |