summaryrefslogtreecommitdiff
path: root/lib/chef/provider.rb
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-07-21 16:47:26 -0600
committerJohn Keiser <john@johnkeiser.com>2015-07-27 09:38:25 -0600
commit9b957381e30423c32a52e3b9bb6ba2a6b0a09b64 (patch)
tree05305cd9dc6a74e2ab5486fd8b9fe2a2b633d723 /lib/chef/provider.rb
parent5e1567fdeb2b0693000fde7d702c106dc51b335c (diff)
downloadchef-9b957381e30423c32a52e3b9bb6ba2a6b0a09b64.tar.gz
Make "property_name" in actions load current value as default
Diffstat (limited to 'lib/chef/provider.rb')
-rw-r--r--lib/chef/provider.rb21
1 files changed, 20 insertions, 1 deletions
diff --git a/lib/chef/provider.rb b/lib/chef/provider.rb
index dcfc92645b..43d58740f2 100644
--- a/lib/chef/provider.rb
+++ b/lib/chef/provider.rb
@@ -211,10 +211,29 @@ class Chef
extend Forwardable
define_singleton_method(:to_s) { "#{resource_class} forwarder module" }
define_singleton_method(:inspect) { to_s }
+ # Add a delegator for each explicit property that will get the *current* value
+ # of the property by default instead of the *actual* value.
+ resource.class.properties.each do |name, property|
+ class_eval(<<-EOM, __FILE__, __LINE__)
+ def #{name}(*args, &block)
+ # If no arguments were passed, we process "get" by defaulting
+ # the value to current_resource, not new_resource. This helps
+ # avoid issues where resources accidentally overwrite perfectly
+ # valid stuff with default values.
+ if args.empty? && !block
+ if !new_resource.property_is_set?(__method__) && current_resource
+ return current_resource.public_send(__method__)
+ end
+ end
+ new_resource.public_send(__method__, *args, &block)
+ end
+ EOM
+ end
dsl_methods =
resource.class.public_instance_methods +
resource.class.protected_instance_methods -
- provider_class.instance_methods
+ provider_class.instance_methods -
+ resource.class.properties.keys
def_delegators(:new_resource, *dsl_methods)
end
include @included_resource_dsl_module