summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2021-03-24 19:18:54 -0700
committerLamont Granquist <lamont@scriptkiddie.org>2021-03-24 19:18:54 -0700
commit358d9625aac8d8044ca233490bbadb1f21d174ac (patch)
tree33aea304ef5a2108b02a93721ec46c114cea5da5
parentf9fbeaf7a3224f00d45d19bdb2801dddcb61dccf (diff)
downloadchef-358d9625aac8d8044ca233490bbadb1f21d174ac.tar.gz
Use method_missing for data bag item delegation
This should fix our spec tests breaking in buildkite on the #to_plist method and actually makes DataBagItem's marginally more useful since they'll lazily delegate those kinds of methods which are monkeypatched into Hash as well. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
-rw-r--r--lib/chef/data_bag_item.rb13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index 94cf2a5317..3a4adb84cc 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -44,8 +44,17 @@ class Chef
end
end
- # Define all Hash's instance methods as delegating to @raw_data
- def_delegators(:@raw_data, *(Hash.instance_methods - Object.instance_methods))
+ # delegate missing methods to the @raw_data Hash
+ def method_missing(method_name, *arguments, &block)
+ @raw_data.send(method_name, *arguments, &block)
+ rescue
+ # throw more sensible errors back at the user
+ super
+ end
+
+ def respond_to_missing?(method_name, include_private = false)
+ @raw_data.respond_to?(method_name, include_private) || super
+ end
attr_reader :raw_data