Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.

Commit 33fdd56

Browse files
Jesse CorettaJesse Coretta
Jesse Coretta
authored and
Jesse Coretta
committed
Add Schema.Push convenience method with unit test
1 parent 32f544d commit 33fdd56

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

schema.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,37 @@ func (r Schema) Counters() Counters {
287287
}
288288
}
289289

290+
/*
291+
Push assigns the input instance of [Definition] to the appropriate
292+
underlying collection. The input instance MUST be compliant.
293+
294+
This is a fluent method.
295+
*/
296+
func (r Schema) Push(def Definition) Schema {
297+
if !r.IsZero() && def.Compliant() {
298+
switch def.Type() {
299+
case `ldapSyntax`:
300+
r.LDAPSyntaxes().Push(def)
301+
case `matchingRule`:
302+
r.MatchingRules().Push(def)
303+
case `attributeType`:
304+
r.AttributeTypes().Push(def)
305+
case `matchingRuleUse`:
306+
r.MatchingRuleUses().Push(def)
307+
case `objectClass`:
308+
r.ObjectClasses().Push(def)
309+
case `dITContentRule`:
310+
r.DITContentRules().Push(def)
311+
case `nameForm`:
312+
r.NameForms().Push(def)
313+
case `dITStructureRule`:
314+
r.DITStructureRules().Push(def)
315+
}
316+
}
317+
318+
return r
319+
}
320+
290321
/*
291322
ParseRaw returns an error following an attempt to parse raw into
292323
usable schema definitions. This method operates similarly to the

schema_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,24 @@ func ExampleSchema_Options() {
4848
// Output: true
4949
}
5050

51+
/*
52+
This example demonstrates a convenient means of adding any [Definition]
53+
qualifier, such as an [ObjectClass] instance, to the schema. This is
54+
useful when manual type verification is cumbersome.
55+
*/
56+
func ExampleSchema_Push() {
57+
def := mySchema.NewObjectClass()
58+
def.SetNumericOID(`1.3.6.1.4.1.56521.999.1232`)
59+
def.SetKind(AuxiliaryKind)
60+
def.SetName(`exampleClass`)
61+
62+
mySchema.Push(def)
63+
get := mySchema.ObjectClasses().Get(`exampleClass`)
64+
65+
fmt.Printf("%s\n", get.OID())
66+
// Output: exampleClass
67+
}
68+
5169
func ExampleSchema_Replace_objectClass() {
5270

5371
gon := mySchema.ObjectClasses().Get(`groupOfNames`)

0 commit comments

Comments
 (0)