Skip to content

Commit

Permalink
Bees can now create Events
Browse files Browse the repository at this point in the history
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
penguwin committed Feb 20, 2020
1 parent 0fa9f80 commit be84145
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions bees/bees.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*
* Authors:
* Christian Muehlhaeuser <[email protected]>
* Nicolas Martin <[email protected]>
*/

// Package bees is Beehive's central module system.
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit be84145

Please sign in to comment.