-
Notifications
You must be signed in to change notification settings - Fork 430
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
548ec42
commit cea5dd3
Showing
5 changed files
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package generator | ||
|
||
import "fmt" | ||
|
||
type HelperMethod struct { | ||
Name string | ||
StructName string | ||
ReturnValue string | ||
ReturnType string | ||
} | ||
|
||
func newHelperMethod(name, structName, returnValue, returnType string) *HelperMethod { | ||
return &HelperMethod{ | ||
Name: name, | ||
StructName: structName, | ||
ReturnValue: returnValue, | ||
ReturnType: returnType, | ||
} | ||
} | ||
|
||
func newIDHelperMethod(idKind idPrefix, structName, returnType string) *HelperMethod { | ||
var returnValue string | ||
switch idKind { | ||
case AccountIdentifierPrefix: | ||
returnValue = "NewAccountObjectIdentifier(v.Name)" | ||
case DatabaseIdentifierPrefix: | ||
returnValue = "NewDatabaseObjectIdentifier(v.DatabaseName, v.Name)" | ||
case SchemaIdentifierPrefix: | ||
returnValue = "NewSchemaObjectIdentifier(v.DatabaseName, v.SchemaName, v.Name)" | ||
default: | ||
return nil | ||
} | ||
return newHelperMethod("ID", structName, returnValue, returnType) | ||
} | ||
|
||
func newObjectTypeHelperMethod(structName string) *HelperMethod { | ||
return newHelperMethod("ObjectType", structName, fmt.Sprintf("ObjectType%v", structName), "ObjectType") | ||
} | ||
|
||
func (i *Interface) ID() *Interface { | ||
i.HelperMethods = append(i.HelperMethods, newIDHelperMethod(i.ObjectIdentifierPrefix(), i.NameSingular, i.IdentifierKind)) | ||
return i | ||
} | ||
|
||
func (i *Interface) ObjectType() *Interface { | ||
i.HelperMethods = append(i.HelperMethods, newObjectTypeHelperMethod(i.NameSingular)) | ||
return i | ||
} | ||
|
||
func (i *Interface) ObjectHelperMethods() *Interface { | ||
return i.ID().ObjectType() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{{- /*gotype: github.com/Snowflake-Labs/terraform-provider-snowflake/pkg/sdk/poc/generator.HelperMethod*/ -}} | ||
|
||
func (v *{{ .StructName }}) {{ .Name }}() {{ .ReturnType }} { | ||
return {{ .ReturnValue }} | ||
} |