Skip to content

Commit

Permalink
Rename passes_filters to is_visible in Name
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvkb committed Jul 14, 2023
1 parent c604a88 commit ea02c0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/models/pls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,12 @@ impl Pls {
let entries = path.read_dir().map_err(Exc::IoError)?;
let nodes = entries
.into_iter()
.filter_map(|entry| entry.ok().map(|entry| Node::new(&entry.path())))
.filter(|node| node.passes_filters(&self.args))
.filter_map(|entry| {
entry.ok().and_then(|entry| {
let node = Node::new(&entry.path());
Name::is_visible(&node, &self.args).then_some(node)
})
})
.collect();
Ok(nodes)
} else {
Expand Down
6 changes: 4 additions & 2 deletions src/traits/name.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use crate::config::Args;
use crate::models::Node;
use log::debug;

pub trait Name {
fn passes_filters(&self, args: &Args) -> bool;
fn is_visible(&self, args: &Args) -> bool;

fn ext(&self) -> String;
fn cname(&self) -> String;
Expand All @@ -16,7 +17,8 @@ impl Name for Node<'_> {
/// For a node to pass, it must pass both filter criteria simultaneously,
/// i.e. match the `only` pattern while not matching the `exclude` pattern.
/// If either pattern is unset, the node is assumed to pass that test.
fn passes_filters(&self, args: &Args) -> bool {
fn is_visible(&self, args: &Args) -> bool {
debug!("Checking visibility of \"{self}\" based on name.");
args.only
.as_ref()
.map_or(true, |pat| pat.is_match(self.name.as_bytes()))
Expand Down

0 comments on commit ea02c0d

Please sign in to comment.