コード例 #1
0
ファイル: main.go プロジェクト: apoydence/ledger
func buildFilter(c *cli.Context) database.Filter {
	var results []database.Filter
	for name, factory := range filters.Store() {
		filterArgs := c.StringSlice(fmt.Sprintf("filter-%s", name))
		if len(filterArgs) <= 0 {
			continue
		}

		for _, arg := range filterArgs {
			builtFilter, err := factory.Generate(arg)
			fatalErr(err)
			results = append(results, builtFilter)
		}
	}

	if len(results) == 0 {
		return nil
	}

	return database.CombineFilters(results...)
}
コード例 #2
0
var _ = Describe("CombineFilters", func() {
	var (
		someTransaction *transaction.Transaction
		filter          database.Filter
		mockFilter1     *mockFilter
		mockFilter2     *mockFilter
	)

	BeforeEach(func() {
		someTransaction = &transaction.Transaction{
			Accounts: &transaction.AccountList{},
		}
		mockFilter1 = newMockFilter()
		mockFilter2 = newMockFilter()
		filter = database.CombineFilters(mockFilter1, mockFilter2, nil)
	})

	It("uses the first filter then the second", func() {
		mockFilter1.resultCh <- []*transaction.Account{
			{
				Name: "some-name-1",
			},
		}
		expectedResults := []*transaction.Account{
			{
				Name: "some-name-2",
			},
		}

		mockFilter2.resultCh <- expectedResults