Class: RailsDoctor::ScanResult

Inherits:
Struct
  • Object
show all
Defined in:
lib/rails_doctor/models.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#coverageObject

Returns the value of attribute coverage

Returns:

  • (Object)

    the current value of coverage



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def coverage
  @coverage
end

#findingsObject

Returns the value of attribute findings

Returns:

  • (Object)

    the current value of findings



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def findings
  @findings
end

#finished_atObject

Returns the value of attribute finished_at

Returns:

  • (Object)

    the current value of finished_at



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def finished_at
  @finished_at
end

#hotspotsObject

Returns the value of attribute hotspots

Returns:

  • (Object)

    the current value of hotspots



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def hotspots
  @hotspots
end

#metadataObject

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def 
  @metadata
end

#profileObject

Returns the value of attribute profile

Returns:

  • (Object)

    the current value of profile



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def profile
  @profile
end

#project_rootObject

Returns the value of attribute project_root

Returns:

  • (Object)

    the current value of project_root



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def project_root
  @project_root
end

#raw_outputsObject

Returns the value of attribute raw_outputs

Returns:

  • (Object)

    the current value of raw_outputs



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def raw_outputs
  @raw_outputs
end

#scoreObject

Returns the value of attribute score

Returns:

  • (Object)

    the current value of score



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def score
  @score
end

#skipped_toolsObject

Returns the value of attribute skipped_tools

Returns:

  • (Object)

    the current value of skipped_tools



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def skipped_tools
  @skipped_tools
end

#started_atObject

Returns the value of attribute started_at

Returns:

  • (Object)

    the current value of started_at



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def started_at
  @started_at
end

#tool_runsObject

Returns the value of attribute tool_runs

Returns:

  • (Object)

    the current value of tool_runs



209
210
211
# File 'lib/rails_doctor/models.rb', line 209

def tool_runs
  @tool_runs
end

Instance Method Details

#duration_msObject



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

#summaryObject



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