Class: WebammToRails::Sources::Migrations::ColumnDefinition::Presenter
- Inherits:
-
Object
- Object
- WebammToRails::Sources::Migrations::ColumnDefinition::Presenter
- Defined in:
- lib/webamm_to_rails/sources/migrations/column_definition/presenter.rb
Instance Method Summary collapse
-
#initialize(column:) ⇒ Presenter
constructor
A new instance of Presenter.
- #render ⇒ Object
Constructor Details
#initialize(column:) ⇒ Presenter
Returns a new instance of Presenter.
6 7 8 |
# File 'lib/webamm_to_rails/sources/migrations/column_definition/presenter.rb', line 6 def initialize(column:) @column = column end |
Instance Method Details
#render ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/webamm_to_rails/sources/migrations/column_definition/presenter.rb', line 10 def render return if @column.type == 'file' if @column.type == 'enum_column' base_def = "t.integer :#{@column.name}, null: #{@column.null}" if @column.default.present? index_of_default = @column.values.index(@column.default) base_def += ", default: #{index_of_default}" end base_def else base_def = "t.#{@column.type} :#{@column.name}, null: #{@column.null}" if @column.default.present? && @column.type == 'string' base_def += ", default: '#{@column.default}'" elsif @column.default.present? base_def += ", default: #{@column.default}" end base_def end end |