Skip to content

Commit 82fbcca

Browse files
committed
Implement the builder pattern
1 parent ec5246f commit 82fbcca

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

src/lib.rs

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ pub struct MissingBlobs {
1010
}
1111

1212
impl MissingBlobs {
13-
/// Creates a new MissingBlobs with the given configuration.
14-
pub fn new(recursive: bool) -> Self {
15-
Self { recursive }
13+
/// Creates a new MissingBlobs builder.
14+
pub fn builder() -> MissingBlobsBuilder {
15+
MissingBlobsBuilder::default()
1616
}
1717

18-
/// Searches for blobs in given paths, and display missing dependencies.
18+
/// Searches for blobs in the given paths, and displays missing dependencies.
1919
pub fn run(&self, paths: &[&str]) {
2020
let file_paths: Vec<PathBuf> = if self.recursive {
2121
find_files_recursively(&paths)
@@ -38,6 +38,32 @@ impl MissingBlobs {
3838
}
3939
}
4040

41+
/// The MissingBlobs builder.
42+
pub struct MissingBlobsBuilder {
43+
recursive: bool,
44+
}
45+
46+
impl Default for MissingBlobsBuilder {
47+
fn default() -> Self {
48+
Self { recursive: false }
49+
}
50+
}
51+
52+
impl MissingBlobsBuilder {
53+
/// Builds a MissingBlobs.
54+
pub fn build(&self) -> MissingBlobs {
55+
MissingBlobs {
56+
recursive: self.recursive,
57+
}
58+
}
59+
60+
/// Sets whether to search paths recursively.
61+
pub fn recursive(mut self, enable: bool) -> Self {
62+
self.recursive = enable;
63+
self
64+
}
65+
}
66+
4167
fn find_files(paths: &[&str]) -> Vec<PathBuf> {
4268
let dirs = paths
4369
.iter()

src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ fn main() {
2222
let paths = matches.values_of("PATHS").unwrap().collect::<Vec<_>>();
2323
let recursive = matches.is_present("recursive");
2424

25-
MissingBlobs::new(recursive).run(&paths);
25+
MissingBlobs::builder()
26+
.recursive(recursive)
27+
.build()
28+
.run(&paths);
2629
}

0 commit comments

Comments
 (0)