-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: check control / limit condition
- Loading branch information
1 parent
f0e8ca4
commit 8c14a77
Showing
8 changed files
with
155 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::collections::HashMap; | ||
|
||
use cala_types::{entry::EntryValues, transaction::TransactionValues}; | ||
use cel_interpreter::{CelMap, CelValue}; | ||
|
||
use crate::{cel_context::*, primitives::EntryId}; | ||
|
||
pub struct EvalContext { | ||
transaction: CelValue, | ||
entry_values: HashMap<EntryId, CelValue>, | ||
} | ||
|
||
impl EvalContext { | ||
pub fn new(transaction: &TransactionValues) -> Self { | ||
Self { | ||
transaction: transaction.into(), | ||
entry_values: HashMap::new(), | ||
} | ||
} | ||
|
||
pub fn control_context(&mut self, entry: &EntryValues) -> CelContext { | ||
let entry = self | ||
.entry_values | ||
.entry(entry.id) | ||
.or_insert_with(|| entry.into()); | ||
|
||
let mut vars = CelMap::new(); | ||
vars.insert("transaction", self.transaction.clone()); | ||
vars.insert("entry", entry.clone()); | ||
|
||
let mut context = CelMap::new(); | ||
context.insert("vars", vars); | ||
|
||
let mut ctx = initialize(); | ||
ctx.add_variable("context", context); | ||
|
||
ctx | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters