How to encapsulate formulas

In this section, you will understand how to encapsulate formulas on Ritchie.

What is an encapsulation?

On Ritchie, it is possible to run formulas inside formulas. This process is what we call Formula Encapsulation.

This functionality allows you, for example, to make operations in which you need to run consecutive formulas.

Check out on the following topics how works this encapsulation.

How to encapsulate?

1. Premisse

To perform a formula encapsulation, it is necessary to use the STDIN flag. On the following page, we have a detailed explanation to how this works:

2. Execution

When implementing a formula, the file where the operation is coded needs to execute a command line associated to a formula.‌

The encapsulated formula command line needs to be executed using the STDIN flag, informing the inputs parameters directly on the code.‌

3. Example

The rit publish repo formula has been implemented using formula encapsulation, that you can find its formula implementation.

On the example below, you'll find below how this encapsulation works on the code part.

This formula has been implemented using Shelland the reasoning would be the same for any other programming language.

runFormula() {
if [ "Github" == $PROVIDER ]
echo "🐙 Github provider selected"
echo '{"privacy":"'$PRIVACY'", "project_name":"'$PROJECT_NAME'", "workspace_path":"'$WORKSPACE_PATH'", "version":"'$VERSION'"}' | rit github publish repo --stdin
elif [ "Gitlab" == $PROVIDER ]
echo "🦊 Gitlab provider selected"
echo '{"privacy":"'$PRIVACY'", "project_name":"'$PROJECT_NAME'", "workspace_path":"'$WORKSPACE_PATH'", "version":"'$VERSION'"}' | rit gitlab publish repo --stdin
echo "🤖 Unexpected Provider informed. Check it please and try again."

Here, according to the input informed by the user, two different formulas can be executed:‌

  • rit github publish repo

  • rit gitlab publish repo

To do so, the encapsulated formulas inputs parameters are informed dynamically according to the inputs parameters of the main formula (rit publish repo).

Depending on the operation, the JSON used with the STDIN command could be generated according to other operations performed through the formula execution before executing the encapsulated formula command line.‌

Next steps

You saw in this section how to use formula encapsulation. If you want to keep reading about Ritchie's commands:‌

​👉 Check out the challenges we created to apply all the Ritchie concepts you learned.‌

​👉 Check out our list of commands to see the available automations on our community repo.