Skip to content

Instantly share code, notes, and snippets.

@abrader
Last active June 21, 2017 17:50
Show Gist options
  • Select an option

  • Save abrader/9d4f3a35a619d9d11377a14904b69060 to your computer and use it in GitHub Desktop.

Select an option

Save abrader/9d4f3a35a619d9d11377a14904b69060 to your computer and use it in GitHub Desktop.
Single namevar

Single Namevar

Every type must have at least one mandatory parameter: the namevar. This parameter will uniquely identify each resource of the type on the target system — for example, the path of a file on disk, the name of a user account, or the name of a package. If the user doesn’t specify a value for the namevar when declaring a resource, its value will default to the title of the resource. There are three ways to designate a namevar. Every type must have exactly one parameter that meets exactly one of these criteria:

Option 1: Create a parameter whose name is :name. Since most types just use :name as the namevar, it gets special treatment and will automatically become the namevar.

    newparam(:name) do
      desc "The name of the database."
    end

Option 2: Provide the :namevar => true option as an additional argument to the newparam call. This allows you to use a namevar with a different, more descriptive name (such as the file type’s path parameter).

    newparam(:path, :namevar => true) do
      ...
    end

Option 3: Call the isnamevar method (which takes no arguments) inside the parameter’s code block. This allows you to use a namevar with a different, more descriptive name. There is no practical difference between this and option 2.

    newparam(:path) do
      isnamevar
      ...
    end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment