addBefore method

void addBefore(
  1. String relativeSourceName,
  2. PropertySource newSource
)

Inserts newSource before the property source named relativeSourceName.

Steps performed:

  1. Validates legal placement (cannot insert relative to itself).
  2. Ensures the relative source exists.
  3. Removes any existing instance of newSource.
  4. Inserts at the appropriate index.

Throws:

  • IllegalArgumentException if the relative source is not present.

Example:

sources.addBefore('env', MapPropertySource('fallback', {...}));

Implementation

void addBefore(String relativeSourceName, PropertySource newSource) {
  _assertLegalRelativeAddition(relativeSourceName, newSource);

  return synchronized(_sources, () {
    _removeIfPresent(newSource);
    int index = _assertPresentAndGetIndex(relativeSourceName);
    _addAtIndex(index, newSource);
  });
}