Skip to content

Commit

Permalink
update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobaraujo7 committed Aug 24, 2024
1 parent 8e07c48 commit bedf914
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.0.4
## 0.0.5

* Added must and mustWith

Expand Down
6 changes: 3 additions & 3 deletions lib/src/lucid_validation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ abstract class LucidValidation<E> {
/// final emailValidator = validator.byField('email');
/// String? validationResult = emailValidator('[email protected]');
/// ```
String? Function(String?)? byField(E entity, String key) {
String? Function([String?])? byField(E entity, String key) {
final propSelector = _propSelectors
.where(
(propSelector) => propSelector.builder.key == key,
Expand All @@ -55,9 +55,9 @@ abstract class LucidValidation<E> {

if (propSelector == null) return null;

return (value) {
if (value == null) return null;
return ([_]) {
final builder = propSelector.builder;
final value = propSelector.selector(entity);
final rules = builder._rules.cast<RuleFunc<String, E>>();
for (var rule in rules) {
final result = rule(value, entity);
Expand Down
37 changes: 37 additions & 0 deletions lib/src/validator_builder.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
part of 'lucid_validation.dart';

/// Defines the behavior of rule execution when a validation failure occurs.
///
/// The `CascadeMode` enum is used to control whether the validation process should
/// continue executing subsequent rules after a validation failure is encountered,
/// or stop immediately after the first failure.
///
/// This is useful for optimizing validation performance or ensuring that only the
/// most critical validation rules are checked first, potentially avoiding unnecessary
/// validations after a failure.
///
/// Available Modes:
///
/// - `continueExecution`: All validation rules for a property will be executed, even if one fails.
/// This is the default behavior and is useful when you want to collect all possible validation
/// errors for a property at once.
///
/// - `stopOnFirstFailure`: Validation will stop as soon as the first validation rule fails for
/// a property. This can be useful when you want to ensure that the most critical validation
/// rules are checked first and to avoid redundant checks after a failure.
///
/// Example:
///
/// ```dart
/// ruleFor((user) => user.password, key: 'password')
/// .notEmpty()
/// .minLength(8)
/// .cascade(CascadeMode.stopOnFirstFailure);
/// ```
///
/// In the example above, if the password is empty, the validation will stop immediately,
/// and the `minLength(8)` rule will not be executed. This can be useful for optimizing
/// performance or ensuring that more critical rules are evaluated first.
enum CascadeMode {
/// Continue executing all validation rules for the property, even if one fails.
/// This mode is useful when you want to collect all possible validation errors at once.
continueExecution,

/// Stop executing validation rules for the property as soon as the first failure is encountered.
/// This mode is useful for optimizing validation performance or prioritizing critical checks.
stopOnFirstFailure,
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/validators/equal_validator_validator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension EqualValidator<T, E> on LucidValidationBuilder<T, E> {
/// Adds a validation rule that checks if the value is equal to [comparison].
///
/// [predicate] is a function that returns the value to compare against.
/// [message] is the error message returned if the validation fails. Defaults to "Must be equal to $comparison".
/// [message] is the error message returned if the validation fails.
/// [code] is an optional error code for translation purposes.
///
/// Returns the [LucidValidationBuilder] to allow for method chaining.
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: "A Dart/Flutter package for building strongly typed validation rule
repository: https://github.com/Flutterando/lucid_validation
homepage: https://pub.dev/documentation/lucid_validation/latest/

version: 0.0.4
version: 0.0.5

environment:
sdk: ">=3.0.0 <4.0.0"
Expand Down

0 comments on commit bedf914

Please sign in to comment.