simplify filtering

This commit is contained in:
Alex Yatskov 2018-12-09 12:45:06 -08:00
parent 989bb18482
commit c8e3e98432
3 changed files with 17 additions and 8 deletions

View File

@ -67,9 +67,9 @@ func (ctx *Context) step() {
defer close(ctx.outputFiles)
var err error
var filters []Filter
var filter Filter
if initializer, ok := ctx.plugin.(Initializer); ok {
filters, err = initializer.Initialize(ctx)
filter, err = initializer.Initialize(ctx)
if err != nil {
ctx.goldsmith.fault(ctx.plugin.Name(), nil, err)
return
@ -86,9 +86,16 @@ func (ctx *Context) step() {
defer wg.Done()
for inputFile := range ctx.inputFiles {
accept := processor != nil
for _, filter := range append(ctx.fileFilters, filters...) {
if accept, err = filter.Accept(ctx, inputFile); err != nil {
ctx.goldsmith.fault(filter.Name(), inputFile, err)
var fileFilters []Filter
fileFilters = append(fileFilters, ctx.fileFilters...)
if filter != nil {
fileFilters = append(fileFilters, filter)
}
for _, fileFilter := range fileFilters {
if accept, err = fileFilter.Accept(ctx, inputFile); err != nil {
ctx.goldsmith.fault(fileFilter.Name(), inputFile, err)
return
}
if !accept {

View File

@ -1,7 +1,7 @@
package goldsmith
type Initializer interface {
Initialize(ctx *Context) ([]Filter, error)
Initialize(ctx *Context) (Filter, error)
}
type Processor interface {

View File

@ -2,13 +2,15 @@ package goldsmith
import "path/filepath"
type loader struct{}
type loader struct {
Initializer
}
func (*loader) Name() string {
return "loader"
}
func (*loader) Initialize(ctx *Context) ([]Filter, error) {
func (*loader) Initialize(ctx *Context) (Filter, error) {
infos := make(chan fileInfo)
go scanDir(ctx.goldsmith.sourceDir, infos)