main
1package spec
2
3// establish context (e.g. "when creating a new sparkle")
4// because of (e.g. "with an empty body")
5// it behaves like (e.g. "it returns an error message")
6type Context struct {
7 because BecauseFunc
8 its []ItFunc
9 state map[string]interface{}
10}
11type ContextFunc func(*Context)
12type BecauseFunc func()
13type ItFunc func()
14
15func Establish(x ContextFunc) {
16 context := Context{
17 its: []ItFunc{},
18 because: func() {},
19 state: make(map[string]interface{}),
20 }
21 x(&context)
22 context.because()
23 for _, it := range context.its {
24 it()
25 }
26}
27
28func (c *Context) Because(b BecauseFunc) {
29 c.because = b
30}
31
32func (c *Context) It(it ItFunc) {
33 c.its = append(c.its, it)
34}
35
36func (c *Context) Let(key string, value interface{}) *Context {
37 c.state[key] = value
38 return c
39}
40
41func (c *Context) Set(key string, value interface{}) *Context {
42 return c.Let(key, value)
43}
44
45func (c *Context) Get(key string) interface{} {
46 return c.state[key]
47}