1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use lazy_static::__Deref;
use super::*;
#[derive(Clone, Debug, Getters, MutGetters)]
#[getset(get = "pub", get_mut = "pub")]
pub struct CibouletteResourceTypeBuilder {
relationships: BTreeMap<ArcStr, petgraph::graph::EdgeIndex<u16>>,
relationships_type_to_alias: BTreeMap<ArcStr, ArcStr>,
schema: MessyJsonObject,
ids: CibouletteIdTypeSelector,
name: ArcStr,
}
impl CibouletteResourceTypeBuilder {
pub fn new(name: String, id_type: CibouletteIdTypeSelector, schema: MessyJsonObject) -> Self {
CibouletteResourceTypeBuilder {
relationships: BTreeMap::new(),
relationships_type_to_alias: BTreeMap::new(),
schema,
ids: id_type,
name: ArcStr::from(name),
}
}
fn check_member_name_obj(val: &MessyJsonObject) -> Option<String> {
for (k, v) in val.properties().iter() {
if !crate::member_name::check_member_name(&*k) {
return Some(k.to_string());
}
if let Some(x) = Self::check_member_name(v) {
return Some(x);
}
}
None
}
fn check_member_name(val: &MessyJson) -> Option<String> {
match val.deref() {
MessyJsonInner::Obj(map) => Self::check_member_name_obj(map),
MessyJsonInner::Array(arr) => Self::check_member_name(arr.items()),
_ => None,
}
}
pub fn build(self) -> Result<CibouletteResourceType, CibouletteError> {
if let Some(x) = Self::check_member_name_obj(self.schema()) {
return Err(CibouletteError::InvalidMemberName(x));
}
Ok(CibouletteResourceType::new(
self.name,
self.ids,
self.schema,
))
}
}
impl Ord for CibouletteResourceTypeBuilder {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.name.cmp(&other.name)
}
}
impl PartialOrd for CibouletteResourceTypeBuilder {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.name.cmp(&other.name))
}
}
impl PartialEq for CibouletteResourceTypeBuilder {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
impl Eq for CibouletteResourceTypeBuilder {}