summaryrefslogtreecommitdiff
path: root/lib/chef/resource.rb
diff options
context:
space:
mode:
authorNoah Kantrowitz <noah@coderanger.net>2015-06-26 15:01:23 -0700
committerNoah Kantrowitz <noah@coderanger.net>2015-06-29 10:51:58 -0700
commit116ca7f695fd5ec20bf24cb4114e9b6984a2b5b7 (patch)
treef8feb5ecc289e89acd5081ff29dc928743ba1613 /lib/chef/resource.rb
parent1289161dd9b53a5e3c9f6c601f6552c452a3e5ad (diff)
downloadchef-116ca7f695fd5ec20bf24cb4114e9b6984a2b5b7.tar.gz
Rework Resource#action to match the 12.3 API.
This means it always coerces to an Array. Also ensures that Resource#action= goes through the same validation. Fixes #3604.
Diffstat (limited to 'lib/chef/resource.rb')
-rw-r--r--lib/chef/resource.rb14
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 8d2532dac4..353eaddfa2 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -169,26 +169,24 @@ class Chef
# @param arg [Array[Symbol], Symbol] A list of actions (e.g. `:create`)
# @return [Array[Symbol]] the list of actions.
#
- attr_accessor :action
def action(arg=nil)
if arg
- if arg.is_a?(Array)
- arg = arg.map { |a| a.to_sym }
- else
- arg = arg.to_sym
- end
- Array(arg).each do |action|
+ arg = Array(arg).map(&:to_sym)
+ arg.each do |action|
validate(
{ action: action },
{ action: { kind_of: Symbol, equal_to: allowed_actions } }
)
end
- self.action = arg
+ @action = arg
else
@action
end
end
+ # Alias for normal assigment syntax.
+ alias_method :action=, :action
+
#
# Sets up a notification that will run a particular action on another resource
# if and when *this* resource is updated by an action.