addBefore method
Inserts newSource before the property source named
relativeSourceName.
Steps performed:
- Validates legal placement (cannot insert relative to itself).
- Ensures the relative source exists.
- Removes any existing instance of
newSource. - Inserts at the appropriate index.
Throws:
IllegalArgumentExceptionif 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);
});
}