-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathexploreAll.go
49 lines (41 loc) · 1.44 KB
/
exploreAll.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package selector
import (
"fmt"
"github.com/ipld/go-ipld-prime/datamodel"
)
// ExploreAll is similar to a `*` -- it traverses all elements of an array,
// or all entries in a map, and applies a next selector to the reached nodes.
type ExploreAll struct {
next Selector // selector for element we're interested in
}
// Interests for ExploreAll is nil (meaning traverse everything)
func (s ExploreAll) Interests() []datamodel.PathSegment {
return nil
}
// Explore returns the node's selector for all fields
func (s ExploreAll) Explore(n datamodel.Node, p datamodel.PathSegment) (Selector, error) {
return s.next, nil
}
// Decide always returns false because this is not a matcher
func (s ExploreAll) Decide(n datamodel.Node) bool {
return false
}
// Match always returns false because this is not a matcher
func (s ExploreAll) Match(node datamodel.Node) (datamodel.Node, error) {
return nil, nil
}
// ParseExploreAll assembles a Selector from a ExploreAll selector node
func (pc ParseContext) ParseExploreAll(n datamodel.Node) (Selector, error) {
if n.Kind() != datamodel.Kind_Map {
return nil, fmt.Errorf("selector spec parse rejected: selector body must be a map")
}
next, err := n.LookupByString(SelectorKey_Next)
if err != nil {
return nil, fmt.Errorf("selector spec parse rejected: next field must be present in ExploreAll selector")
}
selector, err := pc.ParseSelector(next)
if err != nil {
return nil, err
}
return ExploreAll{selector}, nil
}