MCPcopy Create free account
hub / github.com/codnect/procyon / Load

Method Load

component/loader.go:54–75  ·  view source on GitHub ↗

Load evaluates the conditions of each component and registers its definition into the container only if all conditions are satisfied. Components that fail condition checks are skipped. Returns an error if any eligible component fails to register.

(ctx context.Context)

Source from the content-addressed store, hash-verified

52// only if all conditions are satisfied. Components that fail condition checks are skipped.
53// Returns an error if any eligible component fails to register.
54func (l *ConditionalLoader) Load(ctx context.Context) error {
55 skipped := make([]*Component, 0)
56
57 for _, comp := range l.components {
58 if !l.evaluator.evaluate(ctx, comp.Conditions()) {
59 skipped = append(skipped, comp)
60 continue
61 }
62
63 def := comp.definition
64 if err := l.container.RegisterDefinition(def); err != nil {
65 return fmt.Errorf("failed to register component %q: %w", def.Name(), err)
66 }
67 }
68
69 if len(skipped) > 0 && len(skipped) < len(l.components) {
70 loader := NewConditionalLoader(l.container, skipped)
71 return loader.Load(ctx)
72 }
73
74 return nil
75}

Callers 1

Calls 5

NewConditionalLoaderFunction · 0.85
evaluateMethod · 0.80
ConditionsMethod · 0.80
RegisterDefinitionMethod · 0.65
NameMethod · 0.65

Tested by 1