-
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bees can now create Events based on the name and a map containing the Placeholders with Names and Values. To do this we use the Event&Placeholder-Descriptor information which given in the Bees Factory Namespace. This will lead to a much shorter declaration of occuring Events in the Bees implementation.
- Loading branch information
Showing
1 changed file
with
37 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
* | ||
* Authors: | ||
* Christian Muehlhaeuser <[email protected]> | ||
* Nicolas Martin <[email protected]> | ||
*/ | ||
|
||
// Package bees is Beehive's central module system. | ||
|
@@ -325,6 +326,42 @@ func (bee *Bee) LogEvent() { | |
bee.lastEvent = time.Now() | ||
} | ||
|
||
// CreateEvent creates an Event for the given name and fills it's Placeholders | ||
// from the given map. This map should be structured like this: | ||
// | ||
// properties := map[string]interface{}{ | ||
// "event0": val0, | ||
// "event1": val1, | ||
// "event2": val2, | ||
// // ... | ||
// } | ||
// | ||
// whereas the map keys correspond to the placeholders name as string and the map | ||
// values correspond to the desired values for the specific placeholder. | ||
func (bee *Bee) CreateEvent(name string, prop map[string]interface{}) Event { | ||
event := Event{ | ||
Bee: bee.Name(), | ||
Name: name, | ||
Options: []Placeholder{}, | ||
} | ||
|
||
// iterate over the Events provided in the Namespace of the bee and match on | ||
// the provided name | ||
for _, ev := range (*factories[bee.Namespace()]).Events() { | ||
if ev.Name == name { | ||
// and create the corresponding Placholder for the Event | ||
for _, pl := range ev.Options { | ||
event.Options = append(event.Options, Placeholder{ | ||
Name: pl.Name, | ||
Value: prop[pl.Name], | ||
Type: pl.Type, | ||
}) | ||
} | ||
} | ||
} | ||
return event | ||
} | ||
|
||
// LogAction logs the last triggered action. | ||
func (bee *Bee) LogAction() { | ||
bee.lastAction = time.Now() | ||
|