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