Module: CareBert::Reporter

Defined in:
lib/care_bert/reporter.rb

Class Method Summary collapse

Class Method Details

.missing_assocs(report) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/care_bert/reporter.rb', line 43

def self.missing_assocs(report)
  puts '-- records - broken instances - model --'
  anything_broken = false
  report.each_key do |klass_name|
    printf "%10d - %16d - %s\n", report[klass_name][:total], report[klass_name][:smell_count], klass_name
    anything_broken = true if report[klass_name][:errors].present?
  end

  if anything_broken
    puts "\n\n"
    puts 'Listing ids of missing model-instances of assocs:'
    puts '-------------------------------------------------------'
    report.each_key do |klass_name|
      if report[klass_name][:errors].present?
        puts "- #{klass_name} --------------"
        sorted_keys = report[klass_name][:errors].keys.map(&:to_i).sort
        puts ">> affected_instances: #{sorted_keys}"
        sorted_keys.each do |record_id|
          printf " -  %s    >> %s\n", record_id, report[klass_name][:errors][record_id.to_s]
        end
      end
    end
  end
end

.table_integrity(report) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/care_bert/reporter.rb', line 25

def self.table_integrity(report)
  puts '-- records - broken instances - model --'
  anything_broken = false
  report.each_key do |klass_name|
    printf "%10d - %16d - %s\n", report[klass_name][:total], report[klass_name][:broken_instances].count, klass_name
    anything_broken = true if report[klass_name][:broken_instances].count > 0
  end

  if anything_broken
    puts "\n\n"
    puts 'Listing ids of broken models:'
    puts '-------------------------------'
    report.each_key do |klass_name|
      printf " -  %s\n    >> %s\n\n", klass_name, report[klass_name][:broken_instances]
    end
  end
end

.validate_models(report) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/care_bert/reporter.rb', line 3

def self.validate_models(report)
  puts '-- records -     smells - model --'
  report.each_key do |klass_name|
    printf "%10d - %10d - %s\n", report[klass_name][:total], report[klass_name][:smell_count], klass_name
  end

  puts "\n\n"

  report.each_key do |klass_name|
    # check if smells present
    if report[klass_name][:errors].present?
      # print klass headline
      puts "#{klass_name}: "
      # sum up ids by error-construct
      report[klass_name][:errors].each do |err, ids|
        puts "#{err} >> #{ids}"
      end
      puts
    end
  end
end