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

Method replaceSubGraph

lang/funcs/structs/for.go:126–168  ·  view source on GitHub ↗
(subgraphInput interfaces.Func)

Source from the content-addressed store, hash-verified

124}
125
126func (obj *ForFunc) replaceSubGraph(subgraphInput interfaces.Func) error {
127 // delete the old subgraph
128 if err := obj.init.Txn.Reverse(); err != nil {
129 return errwrap.Wrapf(err, "could not Reverse")
130 }
131
132 obj.ClearIterBody(obj.lastInputListLength) // XXX: pass in size?
133
134 for i := 0; i < obj.lastInputListLength; i++ {
135 argName := "forInputList"
136
137 inputElemFunc := SimpleFnToDirectFunc(
138 "forInputElem["+strconv.Itoa(i)+"]",
139 &types.FuncValue{
140 V: func(_ context.Context, args []types.Value) (types.Value, error) {
141 if len(args) != 1 {
142 return nil, fmt.Errorf("inputElemFunc: expected a single argument")
143 }
144 arg := args[0]
145
146 list, ok := arg.(*types.ListValue)
147 if !ok {
148 return nil, fmt.Errorf("inputElemFunc: expected a ListValue argument")
149 }
150
151 return list.List()[i], nil
152 },
153 T: types.NewType(fmt.Sprintf("func(%s %s) %s", argName, obj.listType(), obj.ValueType)),
154 },
155 )
156 obj.init.Txn.AddVertex(inputElemFunc)
157
158 obj.init.Txn.AddEdge(subgraphInput, inputElemFunc, &interfaces.FuncEdge{
159 Args: []string{argName},
160 })
161
162 if err := obj.AppendToIterBody(obj.init.Txn, i, inputElemFunc); err != nil {
163 return errwrap.Wrapf(err, "could not call AppendToIterBody()")
164 }
165 }
166
167 return obj.init.Txn.Commit()
168}
169
170func (obj *ForFunc) listType() *types.Type {
171 return types.NewType(fmt.Sprintf("[]%s", obj.ValueType))

Callers 1

CallMethod · 0.95

Calls 9

listTypeMethod · 0.95
WrapfFunction · 0.92
NewTypeFunction · 0.92
SimpleFnToDirectFuncFunction · 0.85
ReverseMethod · 0.65
ListMethod · 0.65
AddVertexMethod · 0.65
AddEdgeMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected