Class: DatabaseConsistency::Writers::SimpleWriter

Inherits:
BaseWriter
  • Object
show all
Defined in:
lib/database_consistency/writers/simple_writer.rb

Overview

The simplest formatter

Instance Attribute Summary

Attributes inherited from BaseWriter

#log_level, #results

Instance Method Summary collapse

Methods inherited from BaseWriter

#debug?, #initialize, write, #write?

Constructor Details

This class inherits a constructor from DatabaseConsistency::Writers::BaseWriter

Instance Method Details

#delimiter ⇒ Object



18
19
20
# File 'lib/database_consistency/writers/simple_writer.rb', line 18

def delimiter
  debug? ? "\n\n" : "\n"
end

#format ⇒ Object



10
11
12
13
14
15
16
# File 'lib/database_consistency/writers/simple_writer.rb', line 10

def format
  results.map do |result|
    next unless write?(result[:status])

    line(result)
  end.tap(&:compact!).map(&:lstrip).delete_if(&:empty?).join(delimiter)
end

#line(result) ⇒ Object



22
23
24
25
26
# File 'lib/database_consistency/writers/simple_writer.rb', line 22

def line(result)
  "#{result[:status]} #{result[:message]}".tap do |str|
    str.concat " #{result[:opts].inspect}" if debug?
  end
end

#write ⇒ Object



6
7
8
# File 'lib/database_consistency/writers/simple_writer.rb', line 6

def write
  puts format
end