MCPcopy
hub / github.com/purpleidea/mgmt / replaceSubGraph

Method replaceSubGraph

lang/funcs/structs/exprif.go:136–158  ·  view source on GitHub ↗
(b bool)

Source from the content-addressed store, hash-verified

134}
135
136func (obj *ExprIfFunc) replaceSubGraph(b bool) error {
137 // delete the old subgraph
138 if err := obj.init.Txn.Reverse(); err != nil {
139 return errwrap.Wrapf(err, "could not Reverse")
140 }
141
142 var f interfaces.Func
143 if b {
144 obj.init.Txn.AddGraph(obj.ThenGraph)
145 f = obj.ThenFunc
146 } else {
147 obj.init.Txn.AddGraph(obj.ElseGraph)
148 f = obj.ElseFunc
149 }
150
151 // create the new subgraph
152 edgeName := OutputFuncArgName
153 edge := &interfaces.FuncEdge{Args: []string{edgeName}}
154 obj.init.Txn.AddVertex(f)
155 obj.init.Txn.AddEdge(f, obj.OutputVertex, edge)
156
157 return obj.init.Txn.Commit()
158}
159
160// Call this func and return the value if it is possible to do so at this time.
161func (obj *ExprIfFunc) Call(ctx context.Context, args []types.Value) (types.Value, error) {

Callers 1

CallMethod · 0.95

Calls 6

WrapfFunction · 0.92
ReverseMethod · 0.65
AddGraphMethod · 0.65
AddVertexMethod · 0.65
AddEdgeMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected