expression type | example output |
---|---|
literal undef | nil |
literal default | "default" |
literal integer | 1 |
literal float | 3.14 |
literal false | false |
literal true | true |
literal string | "hello" |
literal regexp | "/this|that.*/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'spec_helper' | |
# Example rspec_puppet function rspec test (i.e. subject is the function 'min') | |
# This works for other rspec subjects as well as a compiler is always involved. | |
# This kind of mocking can be required when it is not enough to simply override | |
# a function with another implementation (which can be done with a `let(:pre_condition) { 'function min($x, $y) { ... }'}` | |
# | |
# The main difficulty that this overcomes is the need to let the compiler initialize and | |
# create the context in which it will operate before making any mocks. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StringJoiner joiner = new StringJoiner(","); | |
for (Item item : list) { | |
joiner.add(item.toString()); | |
} | |
return joiner.toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
'name': 'bug', | |
'color': 'd63230', | |
'desc': 'Does not work (according to specification)' | |
}, | |
{ | |
'name': 'improvement', | |
'color': '39a9db', | |
'desc': 'improvement - neither bug nor new feature' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myjoin(Array $a, String $delimiter) { | |
$formats = { | |
Array => { | |
# no delimiters = '% ', and 'a' means array | |
format => '% a', | |
separator => $delimiter, | |
# format strings without delimiters = '%s' | |
string_formats => { String => '%s' } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mymodule::my_privates ( | |
Variant[String, Numeric] $key, | |
Hash $options, | |
Puppet::LookupContext $context, | |
) { | |
case $key { | |
'mymodule::secret1' : { Sensitive('There is no Santa on the evening coach') } | |
'mymodule::secret2' : { Sensitive('All your base are belong to us') } | |
default: { $context.not_found } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%- | |
$pin = "release a=${name}" # default value | |
if $pin_release.length > 0 | |
$options = [ | |
if $release.length > 0 { "a=${release}" }, | |
if $codename.length > 0 { "n=${codename}" }, | |
if $release_version.length > 0 { "v=${release_version}"}, | |
if $component.length > 0 { "c=${component}" }, | |
if $originator.length > 0 { "o=${originator}" }, | |
if $label.length > 0 { "l=${label}" }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Puppet::Parser::Functions.newfunction(:default_content, | |
:type => :rvalue, | |
:doc => <<-'ENDOFDOC' | |
Takes an optional content and an optional template name and returns the | |
contents of a file. | |
Examples: | |
$config_file_content = default_content($file_content, $template_location) | |
file { '/tmp/x': |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of local variables set inside of an EPP template | |
# | |
$template = @(EOF) | |
<% | |
# this is an element with arbitrary puppet code | |
$hash = { a => 1, b => 2, c => 3 } | |
-%> | |
The keys are: | |
<%- $hash.each |$key, $value| { -%> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'puppet' | |
# Example of a module setting everything up to perform custom | |
# validation of an AST model produced by parsing puppet source. | |
# | |
module MyValidation | |
module Issues | |
# (see Puppet::Pops::Issues#issue) | |
# This is boiler plate code | |
def self.issue (issue_code, *args, &block) |