summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-03-07 12:47:25 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2017-03-07 12:49:48 -0800
commitb97382985b33050bdd2add585578e442fea9daa5 (patch)
treef98a579eab2429ca06e8be7fef0c32d6b4453250
parent5c63b80bf9e005864fcfcc73a7e822045271f325 (diff)
downloadchef-lcg/chef-resource-properties.tar.gz
convert additional resource methods to propertieslcg/chef-resource-properties
converts sensitive, retries, retry_delay and ignore_failure to properties Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-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")