-
Notifications
You must be signed in to change notification settings - Fork 7
Definitions
[[TOC]]
A definition is the workflow itself. It's the document that describes exactly what tasks will be performed, and in what order.
- name (String) - The name of the definition.
- content (Array) - The process definition.
Mastermind scans strings in process definition for ${...}
placeholders and substitutes them for fields provided by the job or fields added by providers during the execution of the process. Any field interpolated by ${...}
will be the string representation of the value. If the literal value of the field is needed (for instance, if a field holds an array of values), use the $f:
notation instead.
Given the job fields:
{
:name => "Dan Ryan",
:titles => [ "Future Mayor of Lansing, MI", "Thoulght Leader" ]
}
The following definition...
person :name => "${name}", :titles => "$f:titles"
...gets compiled to:
person :name => "Dan Ryan", :titles => [ "Future Mayor of Lansing, MI", "Thoulght Leader" ]
Definition.new(
:name => "standard syntax",
:content => %q{
run_ssh host: '${host}',
user: '${user}',
key_data: '${key_data}',
command: '${command}'
}
).to_pdef
# => compiled definition
#
# ["define",
# {"name"=>"watee"},
# [["run_ssh",
# {"host"=>"${host}",
# "user"=>"${user}",
# "key_data"=>"${key_data}",
# "command"=>"${command}"},
# []]]]
The previous example uses Ruby 1.9-style hash syntax. If you prefer the look of the "hash rocket", you are more than welcome to use it instead!
Definition.new(
:name => "hash rockets",
:content => %q{
run_ssh :host => '${host}',
:user => '${user}',
:key_data => '${key_data}',
:command => '${command}'
}
).to_pdef
# => compiled definition
#
# ["define",
# {"name"=>"watee"},
# [["run_ssh",
# {"host"=>"${host}",
# "user"=>"${user}",
# "key_data"=>"${key_data}",
# "command"=>"${command}"},
# []]]]
You can even mix in plain old Ruby if you're feeling adventurous!
hosts = %w( host1.example.com host2.example.com host3.example.com )
Definition.new(
:name => "plain ol' ruby!",
:content => %q{
hosts = %w( host1.example.com host2.example.com host3.example.com )
hosts.each do |host|
run_ssh :host => host,
:user => '${user}',
:key_data => '${key_data}',
:command => '${command}'
end
}
).to_pdef
# Same as:
Definition.new(
:name => "plain ol' ruby!",
:content => %q{
run_ssh :host => "host1.example.com",
:user => '${user}',
:key_data => '${key_data}',
:command => '${command}'
run_ssh :host => "host2.example.com",
:user => '${user}',
:key_data => '${key_data}',
:command => '${command}'
run_ssh :host => "host3.example.com",
:user => '${user}',
:key_data => '${key_data}',
:command => '${command}'
}
).to_pdef
# => compiled definition
#
# ["define",
# {"name"=>"watee"},
# [["run_ssh",
# {"host"=>"host1.example.com",
# "user"=>"${user}",
# "key_data"=>"${key_data}",
# "command"=>"${command}"},
# []],
# ["run_ssh",
# {"host"=>"host2.example.com",
# "user"=>"${user}",
# "key_data"=>"${key_data}",
# "command"=>"${command}"},
# []],
# ["run_ssh",
# {"host"=>"host3.example.com",
# "user"=>"${user}",
# "key_data"=>"${key_data}",
# "command"=>"${command}"},
# []]]]