-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Add support for custom views
- Loading branch information
Showing
15 changed files
with
1,029 additions
and
123 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,22 @@ | ||
use crate::config::Configuration; | ||
use crate::engine::state::builds::BuildRepository; | ||
use crate::engine::state::views::ViewRepository; | ||
|
||
pub mod builds; | ||
pub mod views; | ||
|
||
pub struct EngineState { | ||
pub title: String, | ||
pub builds: BuildRepository, | ||
pub views: ViewRepository, | ||
} | ||
|
||
impl EngineState { | ||
pub fn new(config: &Configuration) -> Self { | ||
return EngineState { | ||
title: config.get_title().to_string(), | ||
builds: BuildRepository::new(), | ||
views: ViewRepository::new(config), | ||
}; | ||
} | ||
} |
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,88 @@ | ||
use std::collections::HashMap; | ||
use std::collections::HashSet; | ||
|
||
use crate::config::{Configuration, ViewConfiguration}; | ||
|
||
pub struct ViewRepository { | ||
views: Vec<ViewConfiguration>, | ||
collectors: HashMap<String, HashSet<String>>, | ||
} | ||
|
||
impl ViewRepository { | ||
pub fn new(config: &Configuration) -> Self { | ||
let mut map = HashMap::<String, HashSet<String>>::new(); | ||
if let Some(views) = &config.views { | ||
for view in views.iter() { | ||
let mut collectors = HashSet::<String>::new(); | ||
for collector in view.collectors.iter() { | ||
collectors.insert(collector.clone()); | ||
} | ||
map.insert(view.id.clone(), collectors); | ||
} | ||
} | ||
|
||
Self { | ||
collectors: map, | ||
views: match &config.views { | ||
Some(views) => views.clone(), | ||
None => vec![], | ||
}, | ||
} | ||
} | ||
|
||
pub fn get_collectors(&self, view_id: &str) -> Option<&HashSet<String>> { | ||
self.collectors.get(view_id) | ||
} | ||
|
||
pub fn get_views(&self) -> &Vec<ViewConfiguration> { | ||
&self.views | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
use crate::utils::text::TestVariableProvider; | ||
|
||
#[test] | ||
fn should_return_collectors_for_view() { | ||
// Given | ||
let views = ViewRepository::new( | ||
&Configuration::from_json( | ||
&TestVariableProvider::new(), | ||
r#" | ||
{ | ||
"collectors": [ ], | ||
"views": [ | ||
{ | ||
"id": "foo", | ||
"name": "Foo", | ||
"collectors": [ "a1", "a2" ] | ||
}, | ||
{ | ||
"id": "bar", | ||
"name": "Bar", | ||
"collectors": [ "b1", "b2", "b3" ] | ||
}, | ||
{ | ||
"id": "baz", | ||
"name": "Bar", | ||
"collectors": [ "c1", "c2", "c3", "c4" ] | ||
} | ||
] | ||
} | ||
"#, | ||
) | ||
.unwrap(), | ||
); | ||
|
||
// When | ||
let collectors = views.get_collectors("bar").unwrap(); | ||
|
||
// Then | ||
assert_eq!(3, collectors.len()); | ||
assert!(collectors.contains("b1")); | ||
assert!(collectors.contains("b2")); | ||
assert!(collectors.contains("b3")); | ||
} | ||
} |
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
Oops, something went wrong.