-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/propertyset
- Loading branch information
Showing
41 changed files
with
1,660 additions
and
250 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
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,49 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. | ||
* Licensed under the MIT license. | ||
*/ | ||
|
||
package astmodel | ||
|
||
// InterfaceInjector is a utility for injecting interface implementations into resources and objects | ||
type InterfaceInjector struct { | ||
// visitor is used to do the actual injection | ||
visitor TypeVisitor | ||
} | ||
|
||
// NewInterfaceInjector creates a new interface injector for modifying resources and objects | ||
func NewInterfaceInjector() *InterfaceInjector { | ||
result := &InterfaceInjector{} | ||
|
||
result.visitor = TypeVisitorBuilder{ | ||
VisitObjectType: result.injectInterfaceIntoObject, | ||
VisitResourceType: result.injectInterfaceIntoResource, | ||
}.Build() | ||
|
||
return result | ||
} | ||
|
||
// Inject modifies the passed type definition by injecting the passed function | ||
func (i *InterfaceInjector) Inject(def TypeDefinition, implementation *InterfaceImplementation) (TypeDefinition, error) { | ||
result, err := i.visitor.VisitDefinition(def, implementation) | ||
if err != nil { | ||
return TypeDefinition{}, err | ||
} | ||
return result, nil | ||
} | ||
|
||
// injectFunctionIntoObject takes the function provided as a context and includes it on the | ||
// provided object type | ||
func (i *InterfaceInjector) injectInterfaceIntoObject( | ||
_ *TypeVisitor, ot *ObjectType, ctx interface{}) (Type, error) { | ||
implementation := ctx.(*InterfaceImplementation) | ||
return ot.WithInterface(implementation), nil | ||
} | ||
|
||
// injectFunctionIntoResource takes the function provided as a context and includes it on the | ||
// provided resource type | ||
func (i *InterfaceInjector) injectInterfaceIntoResource( | ||
_ *TypeVisitor, rt *ResourceType, ctx interface{}) (Type, error) { | ||
fn := ctx.(*InterfaceImplementation) | ||
return rt.WithInterface(fn), nil | ||
} |
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
Oops, something went wrong.