Class: TableInspector::Presenter

Inherits:
Object
  • Object
show all
Defined in:
lib/table_inspector/presenter.rb

Direct Known Subclasses

Mysql2, Postgresql, Sqlite3

Defined Under Namespace

Classes: Mysql2, Postgresql, Sqlite3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, option) ⇒ Presenter

Returns a new instance of Presenter.



7
8
9
10
# File 'lib/table_inspector/presenter.rb', line 7

def initialize(klass, option)
  @klass = klass
  @option = option
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/table_inspector/presenter.rb', line 4

def klass
  @klass
end

#optionObject (readonly)

Returns the value of attribute option.



4
5
6
# File 'lib/table_inspector/presenter.rb', line 4

def option
  @option
end

Class Method Details

.currentObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/table_inspector/presenter.rb', line 24

def self.current
  adapter = ApplicationRecord.connection_db_config.adapter.camelize
  available_presenter = %w[Mysql2 Postgresql Sqlite3]

  if available_presenter.include?(adapter)
    "TableInspector::Presenter::#{adapter}".constantize
  else
    TableInspector::Presenter
  end
end

Instance Method Details

#extract_meta(column) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/table_inspector/presenter.rb', line 12

def extract_meta(column)
  if option.colorize
    extract_meta_with_highlight(column)
  else
    extract_meta_without_highlight(column)
  end
end

#headingsObject



20
21
22
# File 'lib/table_inspector/presenter.rb', line 20

def headings
  ordered_keys.map(&:humanize)
end