Class: RailsDoctor::ScanResult
- Inherits:
-
Struct
- Object
- Struct
- RailsDoctor::ScanResult
- Defined in:
- lib/rails_doctor/models.rb
Instance Attribute Summary collapse
-
#coverage ⇒ Object
Returns the value of attribute coverage.
-
#findings ⇒ Object
Returns the value of attribute findings.
-
#finished_at ⇒ Object
Returns the value of attribute finished_at.
-
#hotspots ⇒ Object
Returns the value of attribute hotspots.
-
#metadata ⇒ Object
Returns the value of attribute metadata.
-
#profile ⇒ Object
Returns the value of attribute profile.
-
#project_root ⇒ Object
Returns the value of attribute project_root.
-
#raw_outputs ⇒ Object
Returns the value of attribute raw_outputs.
-
#score ⇒ Object
Returns the value of attribute score.
-
#skipped_tools ⇒ Object
Returns the value of attribute skipped_tools.
-
#started_at ⇒ Object
Returns the value of attribute started_at.
-
#tool_runs ⇒ Object
Returns the value of attribute tool_runs.
Instance Method Summary collapse
- #duration_ms ⇒ Object
- #finish! ⇒ Object
-
#initialize(**kwargs) ⇒ ScanResult
constructor
A new instance of ScanResult.
- #summary ⇒ Object
- #to_h(include_raw: false) ⇒ Object
- #to_json(*args) ⇒ Object
Constructor Details
#initialize(**kwargs) ⇒ ScanResult
Returns a new instance of ScanResult.
224 225 226 227 228 229 230 231 232 233 |
# File 'lib/rails_doctor/models.rb', line 224 def initialize(**kwargs) super self.started_at ||= Time.now self. ||= {} self.findings ||= [] self.tool_runs ||= [] self.skipped_tools ||= [] self.hotspots ||= [] self.raw_outputs ||= {} end |
Instance Attribute Details
#coverage ⇒ Object
Returns the value of attribute coverage
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def coverage @coverage end |
#findings ⇒ Object
Returns the value of attribute findings
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def findings @findings end |
#finished_at ⇒ Object
Returns the value of attribute finished_at
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def finished_at @finished_at end |
#hotspots ⇒ Object
Returns the value of attribute hotspots
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def hotspots @hotspots end |
#metadata ⇒ Object
Returns the value of attribute metadata
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def @metadata end |
#profile ⇒ Object
Returns the value of attribute profile
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def profile @profile end |
#project_root ⇒ Object
Returns the value of attribute project_root
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def project_root @project_root end |
#raw_outputs ⇒ Object
Returns the value of attribute raw_outputs
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def raw_outputs @raw_outputs end |
#score ⇒ Object
Returns the value of attribute score
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def score @score end |
#skipped_tools ⇒ Object
Returns the value of attribute skipped_tools
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def skipped_tools @skipped_tools end |
#started_at ⇒ Object
Returns the value of attribute started_at
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def started_at @started_at end |
#tool_runs ⇒ Object
Returns the value of attribute tool_runs
209 210 211 |
# File 'lib/rails_doctor/models.rb', line 209 def tool_runs @tool_runs end |
Instance Method Details
#duration_ms ⇒ Object
240 241 242 243 244 |
# File 'lib/rails_doctor/models.rb', line 240 def duration_ms return nil unless started_at && finished_at ((finished_at - started_at) * 1000).round end |
#finish! ⇒ Object
235 236 237 238 |
# File 'lib/rails_doctor/models.rb', line 235 def finish! self.finished_at = Time.now self end |
#summary ⇒ Object
246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/rails_doctor/models.rb', line 246 def summary counts = findings.each_with_object(Hash.new(0)) { |finding, memo| memo[finding.severity] += 1 } SEVERITIES.each { |severity| counts[severity] ||= 0 } { profile: profile, duration_ms: duration_ms, finding_count: findings.size, severity_counts: counts, skipped_tools: skipped_tools.map(&:to_h), score: score&.to_h, coverage: coverage&.summary } end |
#to_h(include_raw: false) ⇒ Object
261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/rails_doctor/models.rb', line 261 def to_h(include_raw: false) { schema_version: "1.1", generated_at: (finished_at || Time.now).iso8601, project_root: project_root, profile: profile, metadata: , summary: summary, coverage: coverage&.to_h, findings: findings.map(&:to_h), hotspots: hotspots.map(&:to_h), tool_runs: tool_runs.map { |run| run.to_h(include_raw: include_raw) } } end |
#to_json(*args) ⇒ Object
276 277 278 |
# File 'lib/rails_doctor/models.rb', line 276 def to_json(*args) JSON.pretty_generate(to_h, *args) end |