AddQualifier creates a wrapper over the incoming qualifier which observes the qualification result.
(q Qualifier)
| 1490 | // AddQualifier creates a wrapper over the incoming qualifier which observes the qualification |
| 1491 | // result. |
| 1492 | func (e *evalWatchAttr) AddQualifier(q Qualifier) (Attribute, error) { |
| 1493 | switch qual := q.(type) { |
| 1494 | // By default, the qualifier is either a constant or an attribute |
| 1495 | // There may be some custom cases where the attribute is neither. |
| 1496 | case ConstantQualifier: |
| 1497 | // Expose a method to test whether the qualifier matches the input pattern. |
| 1498 | q = &evalWatchConstQual{ |
| 1499 | ConstantQualifier: qual, |
| 1500 | observer: e.observer, |
| 1501 | adapter: e.Adapter(), |
| 1502 | } |
| 1503 | case *evalWatchAttr: |
| 1504 | // Unwrap the evalWatchAttr since the observation will be applied during Qualify or |
| 1505 | // QualifyIfPresent rather than Eval. |
| 1506 | q = &evalWatchAttrQual{ |
| 1507 | Attribute: qual.InterpretableAttribute, |
| 1508 | observer: e.observer, |
| 1509 | adapter: e.Adapter(), |
| 1510 | } |
| 1511 | case Attribute: |
| 1512 | // Expose methods which intercept the qualification prior to being applied as a qualifier. |
| 1513 | // Using this interface ensures that the qualifier is converted to a constant value one |
| 1514 | // time during attribute pattern matching as the method embeds the Attribute interface |
| 1515 | // needed to trip the conversion to a constant. |
| 1516 | q = &evalWatchAttrQual{ |
| 1517 | Attribute: qual, |
| 1518 | observer: e.observer, |
| 1519 | adapter: e.Adapter(), |
| 1520 | } |
| 1521 | default: |
| 1522 | // This is likely a custom qualifier type. |
| 1523 | q = &evalWatchQual{ |
| 1524 | Qualifier: qual, |
| 1525 | observer: e.observer, |
| 1526 | adapter: e.Adapter(), |
| 1527 | } |
| 1528 | } |
| 1529 | _, err := e.InterpretableAttribute.AddQualifier(q) |
| 1530 | return e, err |
| 1531 | } |
| 1532 | |
| 1533 | // Exec implements the InterpretableV2 interface method. |
| 1534 | func (e *evalWatchAttr) Exec(frame *ExecutionFrame) ref.Val { |
nothing calls this directly
no test coverage detected