@@ -56,33 +56,40 @@ func (c *onFunc) String() string {
5656
5757/******************************* OnProperty **********************************/
5858
59- // CondOnProperty evaluates a condition based on the existence and value of a property
59+ // OnPropertyInterface defines the methods for evaluating a condition based on a property.
60+ type OnPropertyInterface interface {
61+ gs.Condition
62+ MatchIfMissing () OnPropertyInterface
63+ HavingValue (s string ) OnPropertyInterface
64+ }
65+
66+ // onProperty evaluates a condition based on the existence and value of a property
6067// in the context. It allows for complex matching behaviors such as matching missing
6168// properties or evaluating expressions.
62- type CondOnProperty struct {
69+ type onProperty struct {
6370 name string // The name of the property to check.
6471 havingValue string // The expected value or expression to match.
6572 matchIfMissing bool // Whether to match if the property is missing.
6673}
6774
6875// OnProperty creates a condition based on the presence and value of a specified property.
69- func OnProperty (name string ) * CondOnProperty {
70- return & CondOnProperty {name : name }
76+ func OnProperty (name string ) OnPropertyInterface {
77+ return & onProperty {name : name }
7178}
7279
7380// MatchIfMissing sets the condition to match if the property is missing.
74- func (c * CondOnProperty ) MatchIfMissing () * CondOnProperty {
81+ func (c * onProperty ) MatchIfMissing () OnPropertyInterface {
7582 c .matchIfMissing = true
7683 return c
7784}
7885
7986// HavingValue sets the expected value or expression to match.
80- func (c * CondOnProperty ) HavingValue (s string ) * CondOnProperty {
87+ func (c * onProperty ) HavingValue (s string ) OnPropertyInterface {
8188 c .havingValue = s
8289 return c
8390}
8491
85- func (c * CondOnProperty ) Matches (ctx gs.CondContext ) (bool , error ) {
92+ func (c * onProperty ) Matches (ctx gs.CondContext ) (bool , error ) {
8693
8794 // If the context doesn't have the property, handle accordingly.
8895 if ! ctx .Has (c .name ) {
@@ -125,7 +132,7 @@ func (c *CondOnProperty) Matches(ctx gs.CondContext) (bool, error) {
125132 return ok , nil
126133}
127134
128- func (c * CondOnProperty ) String () string {
135+ func (c * onProperty ) String () string {
129136 var sb strings.Builder
130137 sb .WriteString ("OnProperty(name=" )
131138 sb .WriteString (c .name )
0 commit comments