Class: RailsLens::ERD::ColumnTypeFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_lens/erd/column_type_formatter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(column) ⇒ ColumnTypeFormatter

Returns a new instance of ColumnTypeFormatter.



10
11
12
# File 'lib/rails_lens/erd/column_type_formatter.rb', line 10

def initialize(column)
  @column = column
end

Class Method Details

.format(column) ⇒ Object



6
7
8
# File 'lib/rails_lens/erd/column_type_formatter.rb', line 6

def self.format(column)
  new(column).format
end

Instance Method Details

#formatObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_lens/erd/column_type_formatter.rb', line 14

def format
  # Default to the generic type
  case @column.type
  when :integer, :bigint then 'int'
  when :string, :text then 'varchar'
  when :boolean then 'boolean'
  when :decimal, :float then 'decimal'
  when :date then 'date'
  when :datetime, :timestamp then 'datetime'
  when :time then 'time'
  when :binary then 'blob'
  when :json, :jsonb then 'json'
  else
    @column.type.to_s
  end
end