Class: Tasker::Analysis::TemplateGraphAnalyzer
- Inherits:
-
Object
- Object
- Tasker::Analysis::TemplateGraphAnalyzer
- Defined in:
- lib/tasker/analysis/template_graph_analyzer.rb
Overview
Analyzes step template dependencies for workflow design validation
This class provides comprehensive analysis of step template dependencies, including cycle detection, topological sorting, and dependency visualization. It's designed to help with workflow design validation and troubleshooting.
The analyzer performs static analysis on step templates to identify potential issues before workflow execution, including circular dependencies, dependency depth analysis, and parallel execution opportunities.
Instance Attribute Summary collapse
-
#templates ⇒ Array<Tasker::Types::StepTemplate>
readonly
The step templates being analyzed.
Instance Method Summary collapse
-
#analyze ⇒ Hash
Perform comprehensive dependency analysis.
-
#clear_cache! ⇒ void
Clear analysis cache (useful if templates change).
-
#cycles ⇒ Array<Array<String>>
Get detected circular dependencies.
-
#has_cycles? ⇒ Boolean
Check if the workflow has circular dependencies.
-
#initialize(templates) ⇒ TemplateGraphAnalyzer
constructor
Initialize the analyzer with step templates.
-
#leaves ⇒ Array<String>
Get steps with no dependents (workflow exit points).
-
#levels ⇒ Hash<String, Integer>
Get dependency levels for all steps.
-
#roots ⇒ Array<String>
Get steps with no dependencies (workflow entry points).
-
#topology ⇒ Array<String>
Get topological ordering of steps.
Constructor Details
#initialize(templates) ⇒ TemplateGraphAnalyzer
Initialize the analyzer with step templates
34 35 36 37 38 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 34 def initialize(templates) @templates = templates @dependency_map = nil @analysis_cache = nil end |
Instance Attribute Details
#templates ⇒ Array<Tasker::Types::StepTemplate> (readonly)
Returns The step templates being analyzed.
29 30 31 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 29 def templates @templates end |
Instance Method Details
#analyze ⇒ Hash
Perform comprehensive dependency analysis
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 51 def analyze return @analysis_cache if @analysis_cache nodes = build_nodes edges = build_edges dependency_map = build_dependency_map cycles = detect_cycles(dependency_map) topology = cycles.empty? ? topological_sort(dependency_map) : [] levels = calculate_dependency_levels(dependency_map, topology) roots = find_root_steps leaves = find_leaf_steps(edges) @analysis_cache = { nodes: nodes, edges: edges, topology: topology, cycles: cycles, levels: levels, roots: roots, leaves: leaves, summary: build_summary(cycles, levels, edges) } end |
#clear_cache! ⇒ void
This method returns an undefined value.
Clear analysis cache (useful if templates change)
120 121 122 123 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 120 def clear_cache! @analysis_cache = nil @dependency_map = nil end |
#cycles ⇒ Array<Array<String>>
Get detected circular dependencies
85 86 87 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 85 def cycles analyze[:cycles] end |
#has_cycles? ⇒ Boolean
Check if the workflow has circular dependencies
78 79 80 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 78 def has_cycles? cycles.any? end |
#leaves ⇒ Array<String>
Get steps with no dependents (workflow exit points)
113 114 115 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 113 def leaves analyze[:leaves] end |
#levels ⇒ Hash<String, Integer>
Get dependency levels for all steps
99 100 101 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 99 def levels analyze[:levels] end |
#roots ⇒ Array<String>
Get steps with no dependencies (workflow entry points)
106 107 108 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 106 def roots analyze[:roots] end |
#topology ⇒ Array<String>
Get topological ordering of steps
92 93 94 |
# File 'lib/tasker/analysis/template_graph_analyzer.rb', line 92 def topology analyze[:topology] end |