/
mod_tree_item_impl.go
66 lines (56 loc) · 1.44 KB
/
mod_tree_item_impl.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package modconfig
import (
"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty/cty"
)
type ModTreeItemImpl struct {
HclResourceImpl
// required to allow partial decoding
ModTreeItemRemain hcl.Body `hcl:",remain" json:"-"`
Mod *Mod `cty:"mod" json:"-"`
Paths []NodePath `column:"path,jsonb" json:"-"`
parents []ModTreeItem
children []ModTreeItem
}
// AddParent implements ModTreeItem
func (b *ModTreeItemImpl) AddParent(parent ModTreeItem) error {
b.parents = append(b.parents, parent)
return nil
}
// GetParents implements ModTreeItem
func (b *ModTreeItemImpl) GetParents() []ModTreeItem {
return b.parents
}
// GetChildren implements ModTreeItem
func (b *ModTreeItemImpl) GetChildren() []ModTreeItem {
return b.children
}
func (b *ModTreeItemImpl) GetPaths() []NodePath {
// lazy load
if len(b.Paths) == 0 {
b.SetPaths()
}
return b.Paths
}
// SetPaths implements ModTreeItem
func (b *ModTreeItemImpl) SetPaths() {
for _, parent := range b.parents {
for _, parentPath := range parent.GetPaths() {
b.Paths = append(b.Paths, append(parentPath, b.FullName))
}
}
}
func (b *ModTreeItemImpl) GetMod() *Mod {
return b.Mod
}
// GetModTreeItemImpl implements ModTreeItem
func (b *ModTreeItemImpl) GetModTreeItemImpl() *ModTreeItemImpl {
return b
}
// CtyValue implements CtyValueProvider
func (b *ModTreeItemImpl) CtyValue() (cty.Value, error) {
if b.disableCtySerialise {
return cty.Zero, nil
}
return GetCtyValue(b)
}