From 0344de7282904262e1682ea3da6bcb1abf0bb267 Mon Sep 17 00:00:00 2001 From: Seth Vargo Date: Wed, 6 Apr 2016 08:10:41 -0400 Subject: [PATCH] Add a section on accessing finalized config --- .../source/docs/plugins/configuration.html.md | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/website/source/docs/plugins/configuration.html.md b/website/source/docs/plugins/configuration.html.md index 3d1bd8dcb..1126cc9ae 100644 --- a/website/source/docs/plugins/configuration.html.md +++ b/website/source/docs/plugins/configuration.html.md @@ -173,3 +173,36 @@ so be sure to turn it into the proper Hash object to return later. The return value is a Ruby Hash object, where the key is a section name, and the value is a list of error messages. These will be displayed by Vagrant. The hash must not contain any values if there are no errors. + +## Accessing + +After all the configuration options are merged and finalized, you will likely +want to access the finalized value in your plugin. The initializer function +varies with each type of plugin, but *most* plugins expose an initializer like +this: + +```ruby +def initialize(machine, config) + @machine = machine + @config = config +end +``` + +When authoring a plugin, simply call `super` in your initialize function to +setup these instance variables: + +```ruby +def initialize(*) + super + + @config.is_now_available + # ...existing code +end + +def my_helper + @config.is_here_too +end +``` + +For examples, take a look at Vagrant's own internal plugins in the `plugins` +folder in Vagrant's source on GitHub.