A condition on profiles, such as "dev, and eu or us", parsed
once and tested against the active profiles.
Profiles are names switched on for a run (prod, eu, test). Code
that must behave differently per profile asks the environment, and
this is the condition it asks with. Most applications write the same
expressions in @Profile('...') or on-profile in config files and
never build one; in code, environment.matchesProfiles([...]) is
shorter. Build a Profiles to keep a parsed condition, or to test it
against profiles that are not an environment's.
An expression is a profile name, or names combined with ! (not), &
(and), | (or) and parentheses. Mixing & and | without parentheses
is an error, as in Spring. Several expressions in one list are joined
with "or".
// Parsed once, checked on every request.
final euTraffic = Profiles.of(['prod & (eu | uk)']);
if (environment.acceptsProfiles(euTraffic)) { ... }
// Without an environment: any test for "is this profile on".
Profiles.of(['dev', '!prod']).matches({'dev'}.contains); // true
Spring (Java):
Profiles euTraffic = Profiles.of("prod & (eu | uk)");
if (environment.acceptsProfiles(euTraffic)) { ... }
Profiles.of("dev", "!prod").matches(Set.of("dev")::contains);
Constructors
-
Profiles.of(List<
String> expressions) -
Parses
expressionsinto one condition that holds when any of them does.factory
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
matches(
bool isProfileActive(String profile)) → bool -
Whether the condition holds, given
isProfileActive, which tells for one profile name whether it is on. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited