Skip to content

Commit

Permalink
ref(pbxproj): abstract PBXFileReference & PBX*Group into one type
Browse files Browse the repository at this point in the history
  • Loading branch information
kkharji committed Jun 12, 2022
1 parent fdaae8a commit 58b5e23
Show file tree
Hide file tree
Showing 16 changed files with 628 additions and 458 deletions.
2 changes: 1 addition & 1 deletion src/pbxproj/object/build/phase/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum PBXBuildPhaseKind {
}

impl PBXBuildPhaseKind {
/// Return string represntation of PBXBuildPhaseKind
/// Return string representation of PBXBuildPhaseKind
pub fn as_isa(&self) -> &str {
match self {
Self::Headers => "PBXHeadersBuildPhase",
Expand Down
30 changes: 20 additions & 10 deletions src/pbxproj/object/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use md5::Digest;

use super::*;
use std::{
cell::RefCell,
cell::{Ref, RefCell},
collections::HashMap,
rc::{Rc, Weak},
};
Expand Down Expand Up @@ -58,14 +58,27 @@ impl PBXObjectCollection {
.collect()
}

/// Get all PBXGroup
pub fn groups<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXGroup>>)> {
fn fs_references<'a>(
&'a self,
predict: fn(Ref<PBXFSReference>) -> bool,
) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
self.iter()
.filter(|o| o.1.is_pbx_group())
.map(|(k, o)| (k.clone(), o.as_pbx_group().unwrap().clone()))
.filter(|o| {
if let Some(fs_reference) = o.1.as_pbxfs_reference() {
predict(fs_reference.borrow())
} else {
false
}
})
.map(|(k, o)| (k.clone(), o.as_pbxfs_reference().unwrap().clone()))
.collect()
}

/// Get all PBXGroup
pub fn groups<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
self.fs_references(|fs_reference| fs_reference.is_group())
}

/// Get all PBXProject
pub fn projects<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXProject>>)> {
self.iter()
Expand All @@ -75,11 +88,8 @@ impl PBXObjectCollection {
}

/// Get all files
pub fn files<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXFileReference>>)> {
self.iter()
.filter(|o| o.1.is_pbx_file_reference())
.map(|(k, o)| (k.clone(), o.as_pbx_file_reference().unwrap().clone()))
.collect()
pub fn files<'a>(&'a self) -> Vec<(String, Rc<RefCell<PBXFSReference>>)> {
self.fs_references(|fs_reference| fs_reference.is_file())
}

/// Get all PBXBuildFile
Expand Down
163 changes: 0 additions & 163 deletions src/pbxproj/object/file/element.rs

This file was deleted.

127 changes: 0 additions & 127 deletions src/pbxproj/object/file/group.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/pbxproj/object/file/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,2 @@
mod container_item;
mod element;
mod group;
mod reference;
mod source_tree;

pub use container_item::*;
pub use element::*;
pub use group::*;
pub use reference::*;
pub use source_tree::*;
Loading

0 comments on commit 58b5e23

Please sign in to comment.