EliziumNet / Loopz

PowerShell iteration utilities with additional tools like the Parameter Set Tools
https://eliziumnet.github.io/Loopz/
MIT License
3 stars 0 forks source link

refactor the compound filter/handler #189

Closed plastikfan closed 2 years ago

plastikfan commented 2 years ago

Actually, on second thoughts, it doesn't look like the loopz filters have to account for files. This is because the iterator functions are primarily concerned with directories. Any client using say invoke-traversedirectory controls file handling as is therefore not a concern of the loopz iterator.

Remove the file methods on the filter drivers.

plastikfan commented 2 years ago

We can define an independent file filtering object that allows files to be filtered by regex or glob. The difference with the file filter is that the user may wish to apply multiple inclusions and multiple exclusions. Supposing we wanted to find all the music files in a directory tree. We would wish to specify something like .flac, .wav, .alac but exclude .mp3 and *.ogg. When dealing with files, we may apply multiple include/exclusion criteria, where as with directories, we have the notion of scopes, which relate to the segments in their path. 2 different types of filtering.

The defined class, wouldnt be used directly by the iterator instances, its more a utility for the client. Since there is nothing special about files with regards to filtering, this filter object should not be called FileFilter, a better name is PolyFilter which aludes to the fact that there may be multiple individual filters. The PolyFilter will work in a similar way to the CompoundDriver and shouldactually be able to re-use the CompoundHandler for its own purpose.

plastikfan commented 2 years ago

The PolyFilter object works in a similar way to the CompoundFilter except there is a slight difference in the handler. The handler is provided with a hashtable of filters, indexed by scope. The PolyFilter's handler should simply contain a non-associative collection of filters.

plastikfan commented 2 years ago

In order to re-use the handler, it needs a slight refactor to avoid code duplication. The current handler assumes the filters are a hashtable

plastikfan commented 2 years ago

This is not complete yet because there are some other dependencies required, which need to be implemented first, so this just lays a bit of groundwork prior to implementing file filtering in full.