platanus / potassium

A Rails application generator by Platanus, inspired by Suspenders
MIT License
232 stars 17 forks source link

Feat/environment variables #435

Closed nicolasguridi closed 1 year ago

nicolasguridi commented 1 year ago

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:

  1. 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.
  2. 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:

  1. 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.
  2. 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.
  3. 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:

  1. Added an environment variables module file to Potassium's assets
  2. Created a recipe for this new module, including tests
  3. Fixed some typos in the contributing guide
  4. Updated changelog