Class: Recheck::Reporter::Json

Inherits:
Base
  • Object
show all
Defined in:
lib/recheck/reporters.rb

Overview

Default

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#around_query, #fetch_record_id, inherited

Constructor Details

#initialize(arg:) ⇒ Json

Returns a new instance of Json.



219
220
221
222
# File 'lib/recheck/reporters.rb', line 219

def initialize(arg:)
  @filename = arg
  @results = {}
end

Class Method Details

.helpObject



215
216
217
# File 'lib/recheck/reporters.rb', line 215

def self.help
  "Outputs JSON-formatted results to a file or stdout. Arg is filename or blank for stdout."
end

Instance Method Details

#around_check(checker:, query:, check:, record:) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/recheck/reporters.rb', line 235

def around_check(checker:, query:, check:, record:)
  result = yield

  # puts "around_check(checker: #{checker}, query: #{query}, check: #{check.inspect}, record: #{record}"
  check ||= query
  @results[checker.class.to_s][check][:counts].increment(result.type)
  case result.type
  when :fail
    @results[checker.class.to_s][check][:fail] << fetch_record_id(result.record)
  when :exception
    @results[checker.class.to_s][check][:exception] << {
      id: fetch_record_id(result.record),
      message: result.exception.message,
      backtrace: result.exception.backtrace
    }
  end
end

#around_checker(checker:, queries:, checks:, check: []) ⇒ Object



224
225
226
227
228
229
230
231
232
233
# File 'lib/recheck/reporters.rb', line 224

def around_checker(checker:, queries:, checks:, check: [])
  @results[checker.class.to_s] = checks.to_h { |method|
    [method, {
      counts: CountStats.new,
      fail: [],
      exception: []
    }]
  }
  yield
end

#around_run(checkers) ⇒ Object



253
254
255
256
257
258
259
260
# File 'lib/recheck/reporters.rb', line 253

def around_run(checkers)
  yield
  if @filename
    File.write(@filename, @results.to_json)
  else
    puts @results.to_json
  end
end

#halt(checker:, query:, error:, check: "meta") ⇒ Object



262
263
264
# File 'lib/recheck/reporters.rb', line 262

def halt(checker:, query:, error:, check: "meta")
  @results[checker.class.to_s][check][:halt] = error.type
end