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.
234 235 236 237 238 239 240 241 242 243 |
# File 'lib/rails_doctor/models.rb', line 234 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
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def coverage @coverage end |
#findings ⇒ Object
Returns the value of attribute findings
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def findings @findings end |
#finished_at ⇒ Object
Returns the value of attribute finished_at
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def finished_at @finished_at end |
#hotspots ⇒ Object
Returns the value of attribute hotspots
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def hotspots @hotspots end |
#metadata ⇒ Object
Returns the value of attribute metadata
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def @metadata end |
#profile ⇒ Object
Returns the value of attribute profile
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def profile @profile end |
#project_root ⇒ Object
Returns the value of attribute project_root
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def project_root @project_root end |
#raw_outputs ⇒ Object
Returns the value of attribute raw_outputs
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def raw_outputs @raw_outputs end |
#score ⇒ Object
Returns the value of attribute score
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def score @score end |
#skipped_tools ⇒ Object
Returns the value of attribute skipped_tools
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def skipped_tools @skipped_tools end |
#started_at ⇒ Object
Returns the value of attribute started_at
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def started_at @started_at end |
#tool_runs ⇒ Object
Returns the value of attribute tool_runs
219 220 221 |
# File 'lib/rails_doctor/models.rb', line 219 def tool_runs @tool_runs end |
Instance Method Details
#duration_ms ⇒ Object
250 251 252 253 254 |
# File 'lib/rails_doctor/models.rb', line 250 def duration_ms return nil unless started_at && finished_at ((finished_at - started_at) * 1000).round end |
#finish! ⇒ Object
245 246 247 248 |
# File 'lib/rails_doctor/models.rb', line 245 def finish! self.finished_at = Time.now self end |
#summary ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/rails_doctor/models.rb', line 256 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
271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/rails_doctor/models.rb', line 271 def to_h(include_raw: false) { schema_version: "1.2", 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
286 287 288 |
# File 'lib/rails_doctor/models.rb', line 286 def to_json(*args) JSON.pretty_generate(to_h, *args) end |