-
-
Notifications
You must be signed in to change notification settings - Fork 212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: allow selectors on *_NAMES
collections
#1143
base: main
Are you sure you want to change the base?
Changes from all commits
a5b714e
73a2508
dd38d5f
0e4f805
8d4e521
21e6aaa
e84a320
f26a5ea
c6a4048
77f4159
280af44
8dbefad
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,7 +80,7 @@ | |
c.Map.Reset() | ||
} | ||
|
||
func (c *NamedCollection) Names(rv variables.RuleVariable) collection.Collection { | ||
func (c *NamedCollection) Names(rv variables.RuleVariable) collection.Keyed { | ||
return &NamedCollectionNames{ | ||
variable: rv, | ||
collection: c, | ||
|
@@ -101,11 +101,41 @@ | |
} | ||
|
||
func (c *NamedCollectionNames) FindRegex(key *regexp.Regexp) []types.MatchData { | ||
panic("selection operator not supported") | ||
var res []types.MatchData | ||
|
||
for k, data := range c.collection.Map.data { | ||
if key.MatchString(k) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use early termination to reduce the indentation. |
||
for _, d := range data { | ||
res = append(res, &corazarules.MatchData{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if MatchData is mutable, if so we probably want to reuse the pointer? |
||
Variable_: c.variable, | ||
Key_: d.key, | ||
Value_: d.key, | ||
}) | ||
} | ||
} | ||
} | ||
return res | ||
} | ||
|
||
func (c *NamedCollectionNames) FindString(key string) []types.MatchData { | ||
panic("selection operator not supported") | ||
var res []types.MatchData | ||
|
||
for k, data := range c.collection.Map.data { | ||
if k == key { | ||
for _, d := range data { | ||
res = append(res, &corazarules.MatchData{ | ||
Variable_: c.variable, | ||
Key_: d.key, | ||
Value_: d.key, | ||
}) | ||
} | ||
} | ||
} | ||
return res | ||
} | ||
|
||
func (c *NamedCollectionNames) Get(key string) []string { | ||
return c.collection.Map.Get(key) | ||
} | ||
|
||
func (c *NamedCollectionNames) FindAll() []types.MatchData { | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -22,6 +22,17 @@ func (v RuleVariable) Name() string { | |||||
} | ||||||
} | ||||||
|
||||||
//CanBeSelected returns true if the variable supports selection (ie, `:foobar`) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
func (v RuleVariable) CanBeSelected() bool { | ||||||
switch v { | ||||||
{{range .}}case {{ .Key }}: | ||||||
return {{ .CanBeSelected }} | ||||||
{{end}} | ||||||
default: | ||||||
return false | ||||||
} | ||||||
} | ||||||
|
||||||
var rulemapRev = map[string]RuleVariable{ | ||||||
{{range .}}"{{ .Value }}": {{ .Key }}, | ||||||
{{end}} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any chance
data
is empty? if so I would handle the empty case before this allocation.