summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-03-08 11:15:54 +0000
committerGitHub <noreply@github.com>2017-03-08 11:15:54 +0000
commit1ce9ea4fc0a38c8852dd2ddfa45be663d5ff64a9 (patch)
treeb3199213f706e45422ecb50cf482fbc3ac8960ea
parentd58ede971714682af48607b80379e428f39a156c (diff)
parentb97382985b33050bdd2add585578e442fea9daa5 (diff)
downloadchef-1ce9ea4fc0a38c8852dd2ddfa45be663d5ff64a9.tar.gz
Merge pull request #5871 from chef/lcg/chef-resource-properties
convert additional resource methods to properties
-rw-r--r--lib/chef/resource.rb24
-rw-r--r--lib/chef/resource/execute.rb8
-rw-r--r--spec/support/shared/unit/execute_resource.rb3
-rw-r--r--spec/unit/resource_spec.rb12
4 files changed, 11 insertions, 36 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index f9fb5926aa..234cd61dd2 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -138,9 +138,6 @@ class Chef
@action = self.class.default_action
@updated = false
@updated_by_last_action = false
- @ignore_failure = false
- @retries = 0
- @retry_delay = 2
@not_if = []
@only_if = []
@source_line = nil
@@ -152,7 +149,6 @@ class Chef
@guard_interpreter = nil
@default_guard_interpreter = :default
@elapsed_time = 0
- @sensitive = false
end
#
@@ -436,10 +432,7 @@ class Chef
# @param arg [Integer] The number of retries.
# @return [Integer] The number of retries.
#
- def retries(arg = nil)
- set_or_return(:retries, arg, kind_of: Integer)
- end
- attr_writer :retries
+ property :retries, Integer, default: 0, desired_state: false
#
# The number of seconds to wait between retries. Default: 2.
@@ -447,10 +440,7 @@ class Chef
# @param arg [Integer] The number of seconds to wait between retries.
# @return [Integer] The number of seconds to wait between retries.
#
- def retry_delay(arg = nil)
- set_or_return(:retry_delay, arg, kind_of: Integer)
- end
- attr_writer :retry_delay
+ property :retry_delay, Integer, default: 2, desired_state: false
#
# Whether to treat this resource's data as sensitive. If set, no resource
@@ -459,10 +449,7 @@ class Chef
# @param arg [Boolean] Whether this resource is sensitive or not.
# @return [Boolean] Whether this resource is sensitive or not.
#
- def sensitive(arg = nil)
- set_or_return(:sensitive, arg, :kind_of => [ TrueClass, FalseClass ])
- end
- attr_writer :sensitive
+ property :sensitive, [ TrueClass, FalseClass ], default: false, desired_state: false
# ??? TODO unreferenced. Delete?
attr_reader :not_if_args
@@ -560,10 +547,7 @@ class Chef
# @param arg [Boolean] Whether to ignore failures.
# @return Whether this resource will ignore failures.
#
- def ignore_failure(arg = nil)
- set_or_return(:ignore_failure, arg, kind_of: [ TrueClass, FalseClass ])
- end
- attr_writer :ignore_failure
+ property :ignore_failure, [ TrueClass, FalseClass ], default: false, desired_state: false
#
# Equivalent to #ignore_failure.
diff --git a/lib/chef/resource/execute.rb b/lib/chef/resource/execute.rb
index c327b00fb6..659fa341b5 100644
--- a/lib/chef/resource/execute.rb
+++ b/lib/chef/resource/execute.rb
@@ -131,13 +131,7 @@ class Chef
property :password, String, sensitive: true
- def sensitive(args = nil)
- if password
- true
- else
- super
- end
- end
+ property :sensitive, [ TrueClass, FalseClass ], default: false, coerce: proc { |x| password ? true : x }
def self.set_guard_inherited_attributes(*inherited_attributes)
@class_inherited_attributes = inherited_attributes
diff --git a/spec/support/shared/unit/execute_resource.rb b/spec/support/shared/unit/execute_resource.rb
index 2c556bb6cd..ae56a9697d 100644
--- a/spec/support/shared/unit/execute_resource.rb
+++ b/spec/support/shared/unit/execute_resource.rb
@@ -132,15 +132,12 @@ shared_examples_for "an execute resource" do
end
it "should be true if the password is non-nil" do
- expect(@resource.sensitive).to eq(false)
@resource.password("we.funk!")
expect(@resource.sensitive).to eq(true)
end
it "should be true if the password is non-nil but the value is explicitly set to false" do
- expect(@resource.sensitive).to eq(false)
@resource.password("we.funk!")
- expect(@resource.sensitive).to eq(true)
@resource.sensitive false
expect(@resource.sensitive).to eq(true)
end
diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb
index 0f8540b855..481a379743 100644
--- a/spec/unit/resource_spec.rb
+++ b/spec/unit/resource_spec.rb
@@ -480,9 +480,9 @@ describe Chef::Resource do
it "should include the default in the hash" do
expect(resource.to_hash.keys.sort).to eq([:a, :allowed_actions, :params, :provider, :updated,
:updated_by_last_action, :before,
- :noop, :ignore_failure, :name, :source_line,
- :action, :retries, :retry_delay, :elapsed_time,
- :default_guard_interpreter, :guard_interpreter, :sensitive].sort)
+ :noop, :name, :source_line,
+ :action, :elapsed_time,
+ :default_guard_interpreter, :guard_interpreter].sort)
expect(resource.to_hash[:name]).to eq "funk"
expect(resource.to_hash[:a]).to eq 1
end
@@ -492,9 +492,9 @@ describe Chef::Resource do
hash = resource.to_hash
expected_keys = [ :allowed_actions, :params, :provider, :updated,
:updated_by_last_action, :before,
- :noop, :ignore_failure, :name, :source_line,
- :action, :retries, :retry_delay, :elapsed_time,
- :default_guard_interpreter, :guard_interpreter, :sensitive ]
+ :noop, :name, :source_line,
+ :action, :elapsed_time,
+ :default_guard_interpreter, :guard_interpreter ]
expect(hash.keys - expected_keys).to eq([])
expect(expected_keys - hash.keys).to eq([])
expect(hash[:name]).to eql("funk")