Module: Snoot::AnalyseRun
- Defined in:
- lib/snoot/analyse_run.rb,
lib/snoot/analyse_run/result.rb,
lib/snoot/analyse_run/decision.rb
Overview
Turns a pending Run into a terminal outcome: orchestrates the three analysers, then selects one finding (or none, or signals failure). ‘invoke` returns an AnalyseRun::Result carrying the terminal Run, the events emitted along the way, and the raw smell set the orchestration produced.
Defined Under Namespace
Classes: Decision, Result, SkippedDocLessSmellWarned
Class Method Summary
collapse
Class Method Details
.analysis_failure(run, failure) ⇒ Object
24
25
26
27
|
# File 'lib/snoot/analyse_run.rb', line 24
def analysis_failure(run, failure)
failed = run.transition_to(:analysis_failed, failure: failure)
Result.new(run: failed, events: [], smells: Set[])
end
|
.complexity_sort_key(hit) ⇒ Object
65
66
67
68
|
# File 'lib/snoot/analyse_run.rb', line 65
def complexity_sort_key(hit)
loc = hit.location
[loc.path.raw, loc.line_start]
end
|
.duplication_sort_key(cluster) ⇒ Object
60
61
62
63
|
# File 'lib/snoot/analyse_run.rb', line 60
def duplication_sort_key(cluster)
locs = cluster.locations
[cluster.signature, locs.map { |loc| loc.path.raw }.min, locs.map(&:line_start).min]
end
|
.invoke(paths, orchestration:) ⇒ Object
16
17
18
19
20
21
22
|
# File 'lib/snoot/analyse_run.rb', line 16
def invoke(paths, orchestration:)
run = Run.new(paths: paths, outcome: :pending)
result = orchestration.analyse(paths)
return analysis_failure(run, result) if result.is_a?(AnalyserFailure)
Decision.new(orchestration: orchestration, sources: result).resolve(run)
end
|
.select_top_finding(findings) ⇒ Object
29
30
31
32
33
|
# File 'lib/snoot/analyse_run.rb', line 29
def select_top_finding(findings)
top_smell(findings.grep(Smell)) ||
top_duplication(findings.grep(DuplicationCluster)) ||
top_complexity(findings.grep(ComplexityHit))
end
|
.smell_sort_key(smell) ⇒ Object
54
55
56
57
58
|
# File 'lib/snoot/analyse_run.rb', line 54
def smell_sort_key(smell)
type = smell.smell_type
loc = smell.location
[type.name, loc.path.raw, loc.line_start]
end
|
.top_by(items, metric:, &sort_key) ⇒ Object
48
49
50
51
52
|
# File 'lib/snoot/analyse_run.rb', line 48
def top_by(items, metric:, &sort_key)
pick = metric.to_proc
max = items.map(&pick).max
items.select { |item| pick.call(item) == max }.min_by(&sort_key)
end
|
.top_complexity(complexities) ⇒ Object
44
45
46
|
# File 'lib/snoot/analyse_run.rb', line 44
def top_complexity(complexities)
top_by(complexities, metric: :score, &method(:complexity_sort_key))
end
|
.top_duplication(clusters) ⇒ Object
40
41
42
|
# File 'lib/snoot/analyse_run.rb', line 40
def top_duplication(clusters)
top_by(clusters, metric: :size, &method(:duplication_sort_key))
end
|
.top_smell(smells) ⇒ Object
35
36
37
38
|
# File 'lib/snoot/analyse_run.rb', line 35
def top_smell(smells)
counts = smells.group_by(&:smell_type).transform_values(&:size)
top_by(smells, metric: ->(smell) { counts[smell.smell_type] }, &method(:smell_sort_key))
end
|