class Nullalign::Reporters::Base
Constants
- GREEN
- RED
- TERMINAL_WIDTH
Public Instance Methods
column_1(model)
click to toggle source
# File lib/nullalign/reporters/base.rb, line 45 def column_1(model) model.name end
column_headers()
click to toggle source
# File lib/nullalign/reporters/base.rb, line 49 def column_headers ["Model", "Table Columns"] end
divider(pad_to = TERMINAL_WIDTH)
click to toggle source
# File lib/nullalign/reporters/base.rb, line 25 def divider(pad_to = TERMINAL_WIDTH) puts "-" * [pad_to, TERMINAL_WIDTH].max end
report(null_constraints_by_model)
click to toggle source
# File lib/nullalign/reporters/base.rb, line 53 def report(null_constraints_by_model) if null_constraints_by_model.empty? report_success(macro) else null_constraints_by_table_name = null_constraints_by_model.map do |model, columns| [column_1(model), model, columns] end.sort_by(&:first) longest_model_length = null_constraints_by_table_name.map(&:first). sort_by(&:length). last. length column_1_header_length = column_headers.first.length longest_model_length = [longest_model_length, column_1_header_length].max report_failure_header(macro, longest_model_length) null_constraints_by_table_name.each do |table_name, model, columns| print model.name.ljust(longest_model_length + 2) puts columns.first.table_name + ": " + columns.map {|x| x.column }.join(', ') end divider(longest_model_length * 2) end puts end
report_failure_header(macro, longest_model_length)
click to toggle source
# File lib/nullalign/reporters/base.rb, line 29 def report_failure_header(macro, longest_model_length) puts use_color(RED) # TODO not using 'macro' but leaving it here in case this gets # rolled into consistency_fail puts "There are presence validators that aren't backed by non-null constraints." use_default_color divider(longest_model_length * 2) column_1_header, column_2_header = column_headers print column_1_header.ljust(longest_model_length + 2) puts column_2_header divider(longest_model_length * 2) end
report_success(macro)
click to toggle source
# File lib/nullalign/reporters/base.rb, line 17 def report_success(macro) use_color(GREEN) # TODO not using 'macro' but leaving it here in case this gets # rolled into consistency_fail puts "Hooray! All presence validators are backed by a non-null constraint." use_default_color end
use_color(code)
click to toggle source
# File lib/nullalign/reporters/base.rb, line 9 def use_color(code) print "\e[#{code}m" end
use_default_color()
click to toggle source
# File lib/nullalign/reporters/base.rb, line 13 def use_default_color use_color(0) end