class DBA::Printer

Attributes

io[R]

Public Class Methods

new(io = STDOUT) click to toggle source
# File lib/dba/printer.rb, line 7
def initialize(io = STDOUT)
  @io = io
end

Public Instance Methods

print(hash)
Alias for: print_row
print_diff(before_lines, after_lines) click to toggle source
print_error(message) click to toggle source
print_indexes(indexes) click to toggle source
print_line() click to toggle source
print_row(hash) click to toggle source
Also aliased as: print
print_schema(table_name, schema_hash) click to toggle source
print_table(name, row_count) click to toggle source
print_usage(program_name, command_parameters) click to toggle source

Private Instance Methods

format(value) click to toggle source
# File lib/dba/printer.rb, line 82
def format(value)
  case value
  when NilClass
    null
  when BigDecimal
    value.to_s('F')
  when Time
    value.strftime('%F %T')
  else
    value.to_s
  end
end
format_column_type(info_hash) click to toggle source
# File lib/dba/printer.rb, line 102
def format_column_type(info_hash)
  return info_hash[:db_type] unless info_hash[:type]
  return info_hash[:type] unless info_hash[:db_type]&.end_with?('[]')
  info_hash[:type].to_s + '[]'
end
format_parameter(type, name) click to toggle source
# File lib/dba/printer.rb, line 95
def format_parameter(type, name)
  case type
  when :req then name
  when :opt then "[#{name}]"
  end
end
muted(text) click to toggle source
# File lib/dba/printer.rb, line 112
def muted(text)
  return text unless io.isatty

  pastel.bright_black(text.to_s)
end
null() click to toggle source
# File lib/dba/printer.rb, line 108
def null
  @null ||= muted('NULL')
end
pastel() click to toggle source
# File lib/dba/printer.rb, line 118
def pastel
  @pastel ||= Pastel.new
end