-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #349 from duckpuppy/use_traits
Create a Pluggable trait to DRY up terraform commands
- Loading branch information
Showing
10 changed files
with
74 additions
and
159 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* The `Pluggable` trait can be used to add plugin management to a class. It | ||
* takes as a type parameter the plugin type it accepts. | ||
*/ | ||
trait Pluggable<T> implements Resettable { | ||
private static plugins = [] | ||
private appliedPlugins = [] | ||
|
||
/** | ||
* Assures that all plugins are applied, and are applied at most once. It | ||
* can be safely called multiple times. | ||
*/ | ||
public applyPlugins() { | ||
def remainingPlugins = plugins - appliedPlugins | ||
|
||
for (T plugin in remainingPlugins) { | ||
plugin.apply(this) | ||
appliedPlugins << plugin | ||
} | ||
} | ||
|
||
/** | ||
* Accepts a plugin of the appropriate type and adds it to the list of plugins. | ||
* | ||
* @param plugin The plugin to add | ||
*/ | ||
public static void addPlugin(T plugin) { | ||
plugins << plugin | ||
} | ||
|
||
public static void setPlugins(plugins) { | ||
this.plugins = plugins | ||
} | ||
|
||
public static getPlugins() { | ||
return plugins | ||
} | ||
|
||
/** | ||
* Reset plugins will reset the plugin list to a default set of plugins. | ||
* | ||
* @param defaultPlugins list of plugins to set, default: [] | ||
*/ | ||
public static void resetPlugins(defaultPlugins = []) { | ||
this.plugins = defaultPlugins.clone() | ||
} | ||
|
||
public static void reset() { | ||
this.resetPlugins() | ||
} | ||
} |
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 |
---|---|---|
@@ -1,3 +1,6 @@ | ||
/** | ||
* `TerraformCommand` is an interface that can be implemented by a class that wraps a Terraform command. | ||
*/ | ||
interface TerraformCommand { | ||
public String getEnvironment() | ||
} |
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.