summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith84@gmail.com>2020-04-27 17:04:52 -0700
committerTim Smith <tsmith84@gmail.com>2020-04-27 17:04:52 -0700
commitf72bb9f8fb5de46814bb49f561f1dcf3539fba6a (patch)
tree3a1b8a71c6fd42e7ea82719adf2d1a6da460c553
parentca662dbb4dfce06cf1eb70694e51ff2c3e41a804 (diff)
downloadchef-f72bb9f8fb5de46814bb49f561f1dcf3539fba6a.tar.gz
Define resource partials
Signed-off-by: Tim Smith <tsmith@chef.io>
-rw-r--r--RELEASE_NOTES.md50
1 files changed, 49 insertions, 1 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 6a0ca2033b..0d410be250 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -295,7 +295,55 @@ This should be linked to from the breaking change above
### Resource Partials
-https://github.com/chef/chef/pull/9632
+Resource partials allow you to define reusable portions of code that can be included in multiple custom resources. This feature is particularly useful when there are common properties, such as authentication properties, that you want to define in a single location, but use for multiple resources. Internally in the Chef Infra Client codebase we've already used this feature to remove duplicate properties from our `subversion` and `git` resources in order to make them easier to maintain.
+
+Resource partials are stored in a cookbook's `/resources` directory just like existing custom resources, but they start with the `_` prefix. They're then called using a new `use` helper within the resource where they're needed:
+
+`resources/_api_auth_properties.rb:`
+
+```ruby
+property :api_endpoint, String
+property :api_key, String
+property :api_retries, Integer
+```
+
+`resources/mything.rb`:
+
+```ruby
+property :another_property, String
+property :yet_another_property, String
+
+use 'api_auth_properties'
+
+action :create do
+ # some create logic
+end
+```
+
+The example above shows a resource partial that contains properties for use in multiple resources. You can also use resource partials to define helper methods that you want to use in your actions instead of defining the same helper methods in each action_class.
+
+`resources/_api_auth_helpers.rb:`
+
+```ruby
+def make_api_call(endpoint, value)
+ # API call code here
+end
+```
+
+`resources/mything.rb`:
+
+```ruby
+property :another_property, String
+property :yet_another_property, String
+
+action :create do
+ # some create logic
+end
+
+action_class do
+ use 'api_auth_helpers'
+end
+```
### after_resource