Potassium-generated apps, like any other web app, rely on environment variables. Typically, these variables are accessed through class constants. However, this approach can lead to certain issues:
In some cases, an environment variable may be relevant to a group of classes rather than a single one. In such cases, it can be challenging to determine where to define the constant, resulting in it being placed arbitrarily in a class.
Since the constant's value is loaded when the class is defined, it can be difficult to mock it using RSpec.
What has been done
Summary:
A dedicated module for environment variables has been created. The benefits of this are:
Centralized location: all environment variables and their constants are now located in a single module, eliminating the need to arbitrarily choose a class to define them in.
Enhanced functionality: by using methods, it becomes possible to format or process environment variables as needed. This is a common requirement, given that environment variables are always strings.
Improved testability: by using methods, the environment variables are evaluated at runtime. This makes it easier to mock the constants containing them during testing.
Commits:
Added an environment variables module file to Potassium's assets
Created a recipe for this new module, including tests
Context
Potassium-generated apps, like any other web app, rely on environment variables. Typically, these variables are accessed through class constants. However, this approach can lead to certain issues:
What has been done
Summary: A dedicated module for environment variables has been created. The benefits of this are:
Commits: