acts_next/model/
branch.rs1use crate::{model::Step, ModelBase, Vars};
2use serde::{Deserialize, Serialize};
3use serde_json::Value as JsonValue;
4
5#[derive(Debug, Clone, Default, Serialize, Deserialize)]
6pub struct Branch {
7 #[serde(default)]
8 pub name: String,
9
10 #[serde(default)]
11 pub id: String,
12
13 #[serde(default)]
14 pub inputs: Vars,
15
16 #[serde(default)]
17 pub outputs: Vars,
18
19 #[serde(default)]
20 pub tag: String,
21
22 #[serde(default)]
23 pub run: Option<String>,
24
25 pub r#if: Option<String>,
26
27 #[serde(default)]
28 pub steps: Vec<Step>,
29
30 #[serde(default)]
31 pub next: Option<String>,
32
33 #[serde(default)]
34 pub r#else: bool,
35
36 #[serde(default)]
37 pub needs: Vec<String>,
38}
39
40impl ModelBase for Branch {
41 fn id(&self) -> &str {
42 &self.id
43 }
44}
45
46impl Branch {
47 pub fn new() -> Self {
48 Default::default()
49 }
50 pub fn with_id(mut self, id: &str) -> Self {
51 self.id = id.to_string();
52 self
53 }
54
55 pub fn with_name(mut self, name: &str) -> Self {
56 self.name = name.to_string();
57 self
58 }
59
60 pub fn with_tag(mut self, tag: &str) -> Self {
61 self.tag = tag.to_string();
62 self
63 }
64
65 pub fn with_input(mut self, name: &str, value: JsonValue) -> Self {
66 self.inputs.insert(name.to_string(), value);
67 self
68 }
69
70 pub fn with_output(mut self, name: &str, value: JsonValue) -> Self {
71 self.outputs.insert(name.to_string(), value);
72 self
73 }
74
75 pub fn with_next(mut self, next: &str) -> Self {
76 self.next = Some(next.to_string());
77 self
78 }
79
80 pub fn with_else(mut self, default: bool) -> Self {
81 self.r#else = default;
82 self
83 }
84
85 pub fn with_if(mut self, r#if: &str) -> Self {
86 self.r#if = Some(r#if.to_string());
87 self
88 }
89
90 pub fn with_run(mut self, run: &str) -> Self {
91 self.run = Some(run.to_string());
92 self
93 }
94
95 pub fn with_step(mut self, build: fn(Step) -> Step) -> Self {
96 let step = Step::default();
97 self.steps.push(build(step));
98 self
99 }
100
101 pub fn with_need(mut self, need: &str) -> Self {
102 self.needs.push(need.to_string());
103 self
104 }
105}