store pattern as a slice of strings
This commit is contained in:
parent
4c174217d1
commit
a2a47293a8
5 changed files with 29 additions and 9 deletions
|
@ -106,11 +106,11 @@ var DefaultDoneHandler lib.StepProc
|
||||||
// action configuration
|
// action configuration
|
||||||
|
|
||||||
type action struct {
|
type action struct {
|
||||||
pattern string
|
pattern lib.Pattern
|
||||||
specs []lib.ActionSpec
|
specs []lib.ActionSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
func (act *action) Pattern() string {
|
func (act *action) Pattern() lib.Pattern {
|
||||||
return act.pattern
|
return act.pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,8 +118,21 @@ func (act *action) Specs() []lib.ActionSpec {
|
||||||
return act.specs
|
return act.specs
|
||||||
}
|
}
|
||||||
|
|
||||||
func ActionConfig(pattern string, specs []lib.ActionSpec) *action {
|
func ActionConfig(pat string, specs []lib.ActionSpec) *action {
|
||||||
return &action{pattern, specs}
|
return &action{
|
||||||
|
pattern: pattern(strings.Split(pat, "|")),
|
||||||
|
specs: specs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
type pattern []string
|
||||||
|
|
||||||
|
func (p pattern) String() string {
|
||||||
|
return strings.Join(p, "|")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p pattern) Slice() []string {
|
||||||
|
return []string(p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// overridable settings
|
// overridable settings
|
||||||
|
|
|
@ -33,7 +33,9 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action {
|
||||||
if match(ac, msg) {
|
if match(ac, msg) {
|
||||||
for _, spec := range ac.Specs() {
|
for _, spec := range ac.Specs() {
|
||||||
act := action{ctx, spec, msg}
|
act := action{ctx, spec, msg}
|
||||||
logging.DebugA(&act).Str("pattern", ac.Pattern()).Msg("action.Select")
|
logging.DebugA(&act).
|
||||||
|
Str("pattern", ac.Pattern().String()).
|
||||||
|
Msg("action.Select")
|
||||||
acts = append(acts, &act)
|
acts = append(acts, &act)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,7 +44,7 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action {
|
||||||
}
|
}
|
||||||
|
|
||||||
func match(ac lib.ActionConfig, msg lib.Message) bool {
|
func match(ac lib.ActionConfig, msg lib.Message) bool {
|
||||||
return ac.Pattern() == msg.Action()
|
return ac.Pattern().Slice()[0] == msg.Action()
|
||||||
//return false
|
//return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,13 @@ type ActionSpec interface {
|
||||||
Receivers() []string
|
Receivers() []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Pattern interface {
|
||||||
|
fmt.Stringer
|
||||||
|
Slice() []string
|
||||||
|
}
|
||||||
|
|
||||||
type ActionConfig interface {
|
type ActionConfig interface {
|
||||||
Pattern() string
|
Pattern() Pattern
|
||||||
Specs() []ActionSpec
|
Specs() []ActionSpec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ func New(args ...string) lib.Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
func SimpleMessage(action string) lib.Message {
|
func SimpleMessage(action string) lib.Message {
|
||||||
return New("standard", action)
|
return New("scopes", action)
|
||||||
}
|
}
|
||||||
|
|
||||||
var Quit = SimpleMessage("quit")
|
var Quit = SimpleMessage("quit")
|
||||||
|
|
|
@ -45,7 +45,7 @@ func MessageTest(t *testing.T) {
|
||||||
var msg lib.Message = message.SimpleMessage("doit")
|
var msg lib.Message = message.SimpleMessage("doit")
|
||||||
t.AssertEqual(msg.Action(), "doit")
|
t.AssertEqual(msg.Action(), "doit")
|
||||||
t.AssertEqual(msg.Head().Action(), "doit")
|
t.AssertEqual(msg.Head().Action(), "doit")
|
||||||
t.AssertEqual(fmt.Sprint(msg), "standard/doit//")
|
t.AssertEqual(fmt.Sprint(msg), "scopes/doit//")
|
||||||
msg = message.New("taskman", "doit", "task", "tsk001")
|
msg = message.New("taskman", "doit", "task", "tsk001")
|
||||||
t.AssertEqual(fmt.Sprint(msg), "taskman/doit/task/tsk001")
|
t.AssertEqual(fmt.Sprint(msg), "taskman/doit/task/tsk001")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue