Class: DBA::Printer
- Inherits:
-
Object
- Object
- DBA::Printer
- Defined in:
- lib/dba/printer.rb
Instance Attribute Summary collapse
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
-
#initialize(io = STDOUT) ⇒ Printer
constructor
A new instance of Printer.
- #print_diff(before_lines, after_lines) ⇒ Object
- #print_error(message) ⇒ Object
- #print_indexes(indexes) ⇒ Object
- #print_line ⇒ Object
- #print_row(hash) ⇒ Object (also: #print)
- #print_schema(table_name, schema_hash) ⇒ Object
- #print_table(name, row_count) ⇒ Object
- #print_usage(program_name, command_parameters) ⇒ Object
Constructor Details
#initialize(io = STDOUT) ⇒ Printer
Returns a new instance of Printer.
7 8 9 |
# File 'lib/dba/printer.rb', line 7 def initialize(io = STDOUT) @io = io end |
Instance Attribute Details
#io ⇒ Object (readonly)
Returns the value of attribute io.
11 12 13 |
# File 'lib/dba/printer.rb', line 11 def io @io end |
Instance Method Details
#print_diff(before_lines, after_lines) ⇒ Object
42 43 44 45 46 47 48 |
# File 'lib/dba/printer.rb', line 42 def print_diff(before_lines, after_lines) removed = before_lines - after_lines removed.each { |line| io.puts pastel.red("- #{line}") } added = after_lines - before_lines added.each { |line| io.puts pastel.bright_black("+ #{line}") } end |
#print_error(message) ⇒ Object
17 18 19 |
# File 'lib/dba/printer.rb', line 17 def print_error() io.puts(pastel.red('ERROR: ' + )) end |
#print_indexes(indexes) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/dba/printer.rb', line 69 def print_indexes(indexes) indexes.each do |index_name, info_hash| fields = [] fields << index_name fields << muted('(' + info_hash.fetch(:columns).map(&:to_s).join(', ') + ')') fields << muted('{unique}') if info_hash[:unique] io.puts fields.join(' ') end end |
#print_line ⇒ Object
13 14 15 |
# File 'lib/dba/printer.rb', line 13 def print_line io.puts end |
#print_row(hash) ⇒ Object Also known as: print
21 22 23 24 25 |
# File 'lib/dba/printer.rb', line 21 def print_row(hash) hash.each do |name, value| io.puts muted("#{name}: ") + format(value) end end |
#print_schema(table_name, schema_hash) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/dba/printer.rb', line 56 def print_schema(table_name, schema_hash) schema_hash.each do |column_name, info_hash| fields = [] fields << "#{table_name}.#{column_name}" fields << muted(format_column_type(info_hash)) fields << muted('{primary}') if info_hash[:primary_key] io.puts fields.join(' ') end io.puts end |
#print_table(name, row_count) ⇒ Object
50 51 52 53 54 |
# File 'lib/dba/printer.rb', line 50 def print_table(name, row_count) rows = muted("#{row_count} rows") io.puts "#{name} #{rows}" end |
#print_usage(program_name, command_parameters) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/dba/printer.rb', line 29 def print_usage(program_name, command_parameters) io.puts "Usage: #{program_name} COMMAND" io.puts command_parameters.each do |command_name, parameters| parameters = parameters.map { |type, name| format_parameter(type, name) }.compact.join(' ').upcase io.puts " #{program_name} #{command_name} #{parameters}" end io.puts end |