This repository was archived by the owner on Dec 1, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -318,6 +318,37 @@ func (r Schema) Push(def Definition) Schema {
318
318
return r
319
319
}
320
320
321
+ /*
322
+ Exists returns a Boolean value indicative of whether the receiver instance
323
+ contains a matching [Definition] type and identifier.
324
+ */
325
+ func (r Schema ) Exists (def Definition ) (exists bool ) {
326
+ if def == nil {
327
+ return
328
+ }
329
+
330
+ switch def .Type () {
331
+ case `ldapSyntax` :
332
+ exists = ! r .LDAPSyntaxes ().Get (def .NumericOID ()).IsZero ()
333
+ case `matchingRule` :
334
+ exists = ! r .MatchingRules ().Get (def .NumericOID ()).IsZero ()
335
+ case `attributeType` :
336
+ exists = ! r .AttributeTypes ().Get (def .NumericOID ()).IsZero ()
337
+ case `matchingRuleUse` :
338
+ exists = ! r .MatchingRuleUses ().Get (def .NumericOID ()).IsZero ()
339
+ case `objectClass` :
340
+ exists = ! r .ObjectClasses ().Get (def .NumericOID ()).IsZero ()
341
+ case `dITContentRule` :
342
+ exists = ! r .DITContentRules ().Get (def .NumericOID ()).IsZero ()
343
+ case `nameForm` :
344
+ exists = ! r .NameForms ().Get (def .NumericOID ()).IsZero ()
345
+ case `dITStructureRule` :
346
+ exists = ! r .DITStructureRules ().Get (def .(DITStructureRule ).RuleID ()).IsZero ()
347
+ }
348
+
349
+ return
350
+ }
351
+
321
352
/*
322
353
ParseRaw returns an error following an attempt to parse raw into
323
354
usable schema definitions. This method operates similarly to the
Original file line number Diff line number Diff line change @@ -66,6 +66,12 @@ func ExampleSchema_Push() {
66
66
// Output: exampleClass
67
67
}
68
68
69
+ func ExampleSchema_Exists () {
70
+ var def Definition = mySchema .LDAPSyntaxes ().Get (`integer` )
71
+ fmt .Println (mySchema .Exists (def ))
72
+ // Output: true
73
+ }
74
+
69
75
func ExampleSchema_Replace_objectClass () {
70
76
71
77
gon := mySchema .ObjectClasses ().Get (`groupOfNames` )
@@ -203,6 +209,7 @@ func TestSchema_codecov(t *testing.T) {
203
209
mySchema .DITStructureRules ().Index (0 ),
204
210
} {
205
211
mySchema .Replace (def )
212
+ mySchema .Exists (def )
206
213
}
207
214
208
215
mySchema .Replace (LDAPSyntax {})
You can’t perform that action at this time.
0 commit comments