Skip to content

Commit

Permalink
COLDBOX-1296 #resolve
Browse files Browse the repository at this point in the history
New flow peek() method to do fluent peeks in objects
  • Loading branch information
lmajano committed Sep 29, 2024
1 parent 652b80b commit a8519c3
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions system/core/delegates/Flow.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,28 @@
* ---
* This component is mostly used as a delegate to have flow control methods for fluent beauty
*/
component singleton {
component {

/**
* This function will execute the target closure and return the delegated object so you
* can continue chaining.
* <pre>
* // Example Flow
* user
* .setName( "Luis" )
* .setAge( 21 )
* .peek( user => println( user.getName() ) )
* .setEmail( "lmajano@ortus.com" )
* </pre>
*
* @target The closure to execute with the delegate. We pass the target of the delegate as the first argument.
*
* @return Returns itself
*/
function peek( required target ) cbMethod{
arguments.target( $parent );
return $parent;
}

/**
* This function evaluates the target boolean expression and if `true` it will execute the `success` closure
Expand All @@ -26,7 +47,7 @@ component singleton {
} else if ( !isNull( arguments.failure ) ) {
arguments.failure();
}
return this;
return $parent;
}

/**
Expand All @@ -49,7 +70,7 @@ component singleton {
} else if ( !isNull( arguments.failure ) ) {
arguments.failure();
}
return this;
return $parent;
}

/**
Expand All @@ -75,7 +96,7 @@ component singleton {
detail = arguments.detail
);
}
return this;
return $parent;
}

/**
Expand All @@ -101,7 +122,7 @@ component singleton {
detail = arguments.detail
);
}
return this;
return $parent;
}

/**
Expand Down

0 comments on commit a8519c3

Please sign in to comment.