Skip to content

Commit 54f3f59

Browse files
committed
Conditions #31
- Refactor VariablePart to simplify it. - Implement `ConditionVariableVisitor` to retrieve variables used in a condition. - Implement data substitution in condition evaluation.
1 parent 2753dbd commit 54f3f59

File tree

2 files changed

+8
-32
lines changed

2 files changed

+8
-32
lines changed

lib/src/api/models/condition.dart

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,9 @@ class VariablePart extends ExpressionPart {
188188
/// the actual string interpolated with variables.
189189
final String valueString;
190190

191-
/// name of the variable
192-
final String variableName;
193-
194-
/// json path to access data from the variable.
195-
final String? jsonPath;
196-
197191
/// Creates a variable part.
198192
VariablePart({
199-
required this.variableName,
200193
required this.valueString,
201-
this.jsonPath,
202194
});
203195

204196
/// Factory constructor for creating a new [VariablePart] instance from
@@ -208,19 +200,15 @@ class VariablePart extends ExpressionPart {
208200

209201
/// Duplicates the variable part with the provided values.
210202
VariablePart copyWith({
211-
String? variableName,
212203
String? valueString,
213-
String? jsonPath,
214204
}) {
215205
return VariablePart(
216-
variableName: variableName ?? this.variableName,
217206
valueString: valueString ?? this.valueString,
218-
jsonPath: jsonPath ?? this.jsonPath,
219207
);
220208
}
221209

222210
@override
223-
List<Object?> get props => [variableName, jsonPath];
211+
List<Object?> get props => [valueString];
224212

225213
@override
226214
Map toJson() => _$VariablePartToJson(this)..['type'] = 'Variable';
@@ -614,9 +602,10 @@ abstract interface class ExpressionVisitor<R> {
614602

615603
/// An interface for evaluating expression parts.
616604
abstract interface class ExpressionPartVisitor<R> {
617-
/// Evaluates the expression part and returns the result.
605+
/// Evaluates the raw value expression part and returns the result.
618606
R? visitRawValuePart(RawValuePart part);
619607

620-
/// Evaluates the expression part group and returns the result.
608+
/// Evaluates the variable value expression part and returns the value of the
609+
/// variable.
621610
R? visitVariablePart(VariablePart part);
622611
}

lib/src/api/models/condition.g.dart

Lines changed: 4 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)