aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/zclconf/go-cty/cty/path.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/zclconf/go-cty/cty/path.go')
-rw-r--r--vendor/github.com/zclconf/go-cty/cty/path.go42
1 files changed, 42 insertions, 0 deletions
diff --git a/vendor/github.com/zclconf/go-cty/cty/path.go b/vendor/github.com/zclconf/go-cty/cty/path.go
index bf1a7c1..b314449 100644
--- a/vendor/github.com/zclconf/go-cty/cty/path.go
+++ b/vendor/github.com/zclconf/go-cty/cty/path.go
@@ -71,6 +71,48 @@ func (p Path) GetAttr(name string) Path {
71 return ret 71 return ret
72} 72}
73 73
74// Equals compares 2 Paths for exact equality.
75func (p Path) Equals(other Path) bool {
76 if len(p) != len(other) {
77 return false
78 }
79
80 for i := range p {
81 pv := p[i]
82 switch pv := pv.(type) {
83 case GetAttrStep:
84 ov, ok := other[i].(GetAttrStep)
85 if !ok || pv != ov {
86 return false
87 }
88 case IndexStep:
89 ov, ok := other[i].(IndexStep)
90 if !ok {
91 return false
92 }
93
94 if !pv.Key.RawEquals(ov.Key) {
95 return false
96 }
97 default:
98 // Any invalid steps default to evaluating false.
99 return false
100 }
101 }
102
103 return true
104
105}
106
107// HasPrefix determines if the path p contains the provided prefix.
108func (p Path) HasPrefix(prefix Path) bool {
109 if len(prefix) > len(p) {
110 return false
111 }
112
113 return p[:len(prefix)].Equals(prefix)
114}
115
74// GetAttrPath is a convenience method to start a new Path with a GetAttrStep. 116// GetAttrPath is a convenience method to start a new Path with a GetAttrStep.
75func GetAttrPath(name string) Path { 117func GetAttrPath(name string) Path {
76 return Path{}.GetAttr(name) 118 return Path{}.GetAttr(name)