dsntk_workspace/
workspaces.rs1use crate::builder::WorkspaceBuilder;
4use crate::errors::*;
5use antex::ColorMode;
6use dsntk_common::Result;
7use dsntk_feel::context::FeelContext;
8use dsntk_feel::values::Value;
9use dsntk_model_evaluator::ModelEvaluator;
10use std::collections::HashMap;
11use std::path::PathBuf;
12use std::sync::Arc;
13
14pub struct Workspaces {
16 pub(crate) invocables: HashMap<String, (String, String, String, String)>,
18 pub(crate) evaluators: HashMap<String, Arc<ModelEvaluator>>,
20}
21
22impl Workspaces {
23 pub fn new(dirs: &[PathBuf], colors: ColorMode, verbose: bool) -> Self {
25 let builder = WorkspaceBuilder::new(dirs, colors, verbose);
26 Self {
27 invocables: builder.invocables,
28 evaluators: builder.evaluators,
29 }
30 }
31
32 pub fn evaluate(&self, invocable_path: &str, input_data: &FeelContext) -> Result<Value> {
34 if let Some((workspace_name, model_namespace, model_name, invocable_name)) = self.invocables.get(invocable_path)
35 && let Some(evaluator) = self.evaluators.get(workspace_name)
36 {
37 return Ok(evaluator.evaluate_invocable(model_namespace, model_name, invocable_name, input_data));
38 }
39 Err(err_invocable_not_found(invocable_path))
40 }
41}