Class: ColumnsTrace::LogReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/columns_trace/log_reporter.rb

Overview

Reporter that reports into the provided logger.

Instance Method Summary collapse

Constructor Details

#initialize(logger) ⇒ LogReporter

Returns a new instance of LogReporter.



6
7
8
# File 'lib/columns_trace/log_reporter.rb', line 6

def initialize(logger)
  @logger = logger
end

Instance Method Details

#report(title, created_records) ⇒ Object

Main reporter’s method

Parameters:

  • title (String)

    title of the reporting, e.g. controller action etc

  • created_records (Array<ColumnsTrace::CreatedRecord>)

    items that hold metadata about created records



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/columns_trace/log_reporter.rb', line 16

def report(title, created_records)
  lines = []

  created_records.group_by(&:model).each do |model, grouped_created_records|
    lines.concat(lines_for_created_records(model, grouped_created_records))
  end

  if lines.any?
    @logger.info("#{title}\n#{lines.join("\n")}")
  end
end