generated from snivilised/astrolib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(filter): create hybrid scheme (#164)
- Loading branch information
1 parent
0c2d20b
commit 59f3844
Showing
36 changed files
with
653 additions
and
491 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package filter | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// ❌ InvalidNotificationMuteRequested error: this scenario should | ||
// never happen, if it does then its an internal issue to be | ||
// addressed here in the filter plugin. | ||
|
||
// IsNoSubordinateHybridSchemesDefinedError uses errors.Is to check | ||
// if the err's error tree contains the core error: | ||
// InvalidNotificationMuteRequestedError | ||
func IsNoSubordinateHybridSchemesDefinedError(err error) bool { | ||
return errors.Is(err, ErrNoSubordinateHybridSchemesDefined) | ||
} | ||
|
||
var ErrNoSubordinateHybridSchemesDefined = errors.New( | ||
"invalid filter scheme, both primary and child not set", | ||
) |
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,49 @@ | ||
package filter | ||
|
||
import ( | ||
"github.com/snivilised/traverse/core" | ||
"github.com/snivilised/traverse/enums" | ||
"github.com/snivilised/traverse/internal/measure" | ||
"github.com/snivilised/traverse/internal/third/lo" | ||
"github.com/snivilised/traverse/internal/types" | ||
"github.com/snivilised/traverse/pref" | ||
) | ||
|
||
type customScheme struct { | ||
common | ||
filter core.TraverseFilter | ||
} | ||
|
||
func (s *customScheme) create() error { | ||
s.filter = s.o.Filter.Custom | ||
|
||
if s.o.Filter.Sink != nil { | ||
s.o.Filter.Sink(pref.FilterReply{ | ||
Node: s.filter, | ||
}) | ||
} | ||
|
||
return s.filter.Validate() | ||
} | ||
|
||
func (s *customScheme) next(node *core.Node, | ||
_ types.Inspection, | ||
) (bool, error) { | ||
return matchNext(s.filter, node, s.crate) | ||
} | ||
|
||
func matchNext(filter core.TraverseFilter, | ||
node *core.Node, crate *measure.Crate, | ||
) (bool, error) { | ||
matched := filter.IsMatch(node) | ||
|
||
if !matched { | ||
filteredOutMetric := lo.Ternary(node.IsFolder(), | ||
enums.MetricNoFoldersFilteredOut, | ||
enums.MetricNoFilesFilteredOut, | ||
) | ||
crate.Mums[filteredOutMetric].Tick() | ||
} | ||
|
||
return matched, nil | ||
} |
Oops, something went wrong.