Add scoped inspection views
This commit is contained in:
33
internal/engine/inspection_view.go
Normal file
33
internal/engine/inspection_view.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package engine
|
||||
|
||||
// InspectionView borrows an inspection and selects a canonical reporting scope.
|
||||
type InspectionView struct {
|
||||
inspection *Inspection
|
||||
scope Path
|
||||
}
|
||||
|
||||
func NewInspectionView(inspection *Inspection, scope Path) (InspectionView, bool) {
|
||||
if inspection == nil || !scope.valid() {
|
||||
return InspectionView{}, false
|
||||
}
|
||||
normalized, err := ParsePath(scope.String())
|
||||
if err != nil {
|
||||
return InspectionView{}, false
|
||||
}
|
||||
return InspectionView{inspection: inspection, scope: normalized}, true
|
||||
}
|
||||
|
||||
func (v InspectionView) Inspection() *Inspection { return v.inspection }
|
||||
|
||||
func (v InspectionView) HistoricalPaths() []Path {
|
||||
if v.inspection == nil {
|
||||
return nil
|
||||
}
|
||||
var paths []Path
|
||||
for _, path := range v.inspection.Metadata().HistoricalPaths() {
|
||||
if pathContains(v.scope, path) {
|
||||
paths = append(paths, path)
|
||||
}
|
||||
}
|
||||
return paths
|
||||
}
|
||||
Reference in New Issue
Block a user